• Resolved umahnken

    (@umahnken)


    I need the content of an event to show on the widget. Is it possible to get the full content or the excerpt with function the_content() and how to do? Or is there an other way to do this?

    • This topic was modified 9 months, 2 weeks ago by umahnken.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Darian

    (@d0153)

    Hi @umahnken

    Yes, you can use “the_content()” in getting the description of your event. Additionally, it’s worth noting that events utilize the “tribe_events” post type.

    I hope this helps. Let me know if you have further concerns.

    Thread Starter umahnken

    (@umahnken)

    Thanks, it works ??
    One more question: the_content() stripped all HTML tags from the description. How can I get these tags back?

    Plugin Support tristan083

    (@tristan083)

    Hi @umahnken ,

    Thank you for your message.

    I’m not sure, but, the_content() is a WordPress function. Have you tried using get_the_content() instead?

    I’ve searched around and the following thread might also help: the_content filter doesn’t return html code, any substitute?

    Thread Starter umahnken

    (@umahnken)

    Here is a solution which brings back tags like <b> or <i>, but unfortunately not <p>…</p> or <br>:

    
    function get_posts_as_array( $loop_args = array() ) {
    $posts_output = array();
    
    $defaults = array(
        'post_type' => 'tribe_events',
        'post_status'=> 'publish'
    );
    $post_loop_args = wp_parse_args( $loop_args, $defaults );
    
    $post_loop = new WP_Query( $post_loop_args );
    while ( $post_loop->have_posts() ) : $post_loop->the_post();
        $single_post_id = get_the_id();
        $single_post    = array(
            'id'       => $single_post_id,
            'content' =>  apply_filters('the_content', get_the_content($single_post_id))
        );
        array_push( $posts_output, $single_post );
    endwhile;
    
    return $posts_output;
    
    };

    Call this with for example the following code:

    
    $posts_array = get_posts_as_array(); 
    $content = implode($posts_array[$i]);
    Plugin Support Darian

    (@d0153)

    Hi @umahnken

    Could you update part of your code to the following, and see if that works?

    'content' =>  apply_filters('the_content', wpautop(get_the_content($single_post_id)))

    As always, please test it first on your staging site before applying to your live site.

    Let me know how it goes.

    Thread Starter umahnken

    (@umahnken)

    Thanks, but This makes no difference …

    Plugin Support masoodak

    (@masoodak)

    Hi @umahnken

    Could you try it this way,

    function get_posts_as_array( $loop_args = array() ) {
    	$posts_output = array();
    
    	$defaults       = array(
    		'post_type'   => 'tribe_events',
    		'post_status' => 'publish'
    	);
    	$post_loop_args = wp_parse_args( $loop_args, $defaults );
    
    	$post_loop = new WP_Query( $post_loop_args );
    	while ( $post_loop->have_posts() ) : $post_loop->the_post();
    		$single_post_id = get_the_ID();
    		$single_post    = array(
    			'id'      => $single_post_id,
    			'content' => apply_filters( 'the_content', get_the_content() )
    		);
    		array_push( $posts_output, $single_post );
    	endwhile;
    
    	// Reset post data to avoid conflicts
    	wp_reset_postdata();
    
    	return $posts_output;
    }

    And call it this way,

    $posts_array = get_posts_as_array();
    $content     = '';
    foreach ( $posts_array as $post ) {
    	$content .= $post['content'];
    }
    echo $content;

    Let us know if this works.

    Thread Starter umahnken

    (@umahnken)

    unfortunately not

    Plugin Support masoodak

    (@masoodak)

    Hi @umahnken

    It’s indeed strange. I tried the same approach on my test site, and it worked fine as the content parsed at the frontend respected <p> and <br> tags.

    Can you run quick conflict testing and check if the content output at the frontend changes behavior on a barebones WordPress installation?

    https://theeventscalendar.com/knowledgebase/testing-for-conflicts/

    Let me know how it goes.

    Thread Starter umahnken

    (@umahnken)

    Hi @masoodak

    Thanks for your help. It’ curious, but suddenly your approach worked with my site. I am sure not have changed anything … But okay ??

    Plugin Support Darian

    (@d0153)

    Hi @umahnken

    Thanks for your confirmation and I’m glad that it is now working.

    If you have a minute, a great review from you would be amazing!

    https://www.ads-software.com/support/plugin/the-events-calendar/reviews/

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to view content in the widget’ is closed to new replies.