0

I have a custom post type for creating popups. I have a loop where I display all the popups and it all works fine, until I try get the content using the_content();

the_title(), the_ID() etc., all work fine.

I'm using SiteOrigin Layout builder to build the content on the popup post type editor, so perhaps there's a conflict with that?

Here is the whole code:

<div id="popup-content">

    <?php
    global $post;

    $popup_args = array(
        'posts_per_page'   => -1,
        'offset'           => 0,
        'orderby'          => 'menu_order',
        'order'            => 'ASC',
        'post_type'        => 'solar-popup',
        'post_status'      => 'publish',
        'suppress_filters' => false
    );
    $get_popups = get_posts($popup_args);

    foreach ($get_popups as $post) :

        setup_postdata( $post );

        $popup_id = get_the_ID();
        $popup_name = get_post_meta($popup_id, '_popup_name', true);
        $popup_width = get_post_meta($popup_id, '_popup_width', true);


        $popup_style = '';
        if ( !empty($popup_width) ) $popup_style = 'max-width:'. $popup_width;

        echo '<div class="popup" data-popup="'. $popup_name .'" style="'. $popup_style .'">';
        echo '<a href="#" class="popup-close"><img class="svg" src="'. get_template_directory_uri() .'/assets/icons/close.svg"></a>';
        echo '<div class="content">';

        the_title();

        // the_content();

        echo '</div>';
        echo '</div>';

    endforeach;

    wp_reset_postdata();
    ?>

</div>

Any help with this would be truly appreciated!

Thank you!

  • Have you tried setting WP_DEBUG to true in your wp-config.php file to see if it gives any clues to your error and have you checked your PHP error logs? – Mat Apr 18 '18 at 12:05
  • where is this code placed? Inside a template file? – Levi Dulstein Apr 18 '18 at 13:26
  • Have you tried get_the_content()? – Peter HvD Apr 18 '18 at 14:02
  • @Mat I hadn't actually tried that, but it didn't show anything relevant when I did now. Just a little PHP notice that I quickly fixed. – Herman Aus Apr 18 '18 at 23:38
  • @LeviDulstein, yes I'm loading it into my header.php file using get_template_part( 'template-parts/content', 'popup' ); get_the_content() doesn't pass it through the_content filter so shortcodes don't display for example. I need it to go through the_content filter because I want the Layout builder formatting to remain intact. – Herman Aus Apr 18 '18 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.