• Hi, I’m using a wp_query to pull through the content of a custom post type.

    I’m using the_title & the_content.

    the_title works perfectly, eg – “post1”, “post2”, “post3” etc

    the_content however is pulling through a custom block from the first post and then outputs the same content for the subsequent posts. Has anyone come across this before?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @jduffell Can you please share your wp_query code so we can help you more precisely? Also share your loop where your are displaying title and content.

    Thank you

    Thread Starter jduffell

    (@jduffell)

    @weboccults sure can ??

    <?php $args = array(
    	'post_type' 	=> 'case-study',
    	'nopaging' 		=> true,
    	'orderby' 		=> 'date',
    	'order' 		=> 'asc',
    	'paged' 		=> $paged,
    ); $wp_query = new WP_Query($args);
    if($wp_query->have_posts()) :
    while($wp_query->have_posts()) :  $wp_query->the_post(); 
    
    the_content();
    
    endwhile; else: ?>
    
    <span class="content">
    
    	Sorry, no matching case studies could be found
    
    </span>
    
    <?php endif; wp_reset_query(); ?>
    Moderator bcworkz

    (@bcworkz)

    I see no problems there. I tested it on my own site to be sure, only changing the CPT to one of my own. The issue lies elsewhere. Is your custom block pulling content from elsewhere? That could be the issue. the_content() output is filtered. It’s possible an added filter is using the same content in every post.

    Thread Starter jduffell

    (@jduffell)

    @bcworkz Nothing I can spot, I’ve stripped out any additional code and it appears to be doing the same, I am using the Advanced Custom Fields plugin, but aside from that, it’s a bit of a head scratcher. A long work around I’ve found is within the loop to parse the blocks, however I’m having to print values from an array into the relevant elements which is long winding and means additional code which is a bit of a pain.

    add_action('acf/init', 'my_acf_init_block_types');
    function my_acf_init_block_types() {
    
        if( function_exists('acf_register_block_type') ) { 
    
            acf_register_block_type(array(
                'name'              => 'case-study',
                'title'             => __('Case Study'),
                'description'       => __('Predefined case study layout'),
                'render_template'   => 'templates/parts/block-case-study.php',
    			'enqueue_assets'  => function() {
    				wp_enqueue_style( 'css', get_template_directory_uri() . '/style/case-study.css' );
    			},
                'category'          => 'formatting',
    			'icon' 				=> array(
    				'background' 		=> '#9FFF9F',
    				'foreground' 		=> '#000000',
    				'src' 				=> 'layout',
    				),
                'mode'				=> 'edit',
            ));
    
        }
    }
    
    Moderator bcworkz

    (@bcworkz)

    Sadly the inner workings of blocks is beyond my comprehension. I suspect there is a flaw in the block’s render code where what the current post is in your loop isn’t getting through to the code. It keeps getting ACF data related to the first post and never gets updated about subsequent posts. But I’m only guessing since I don’t understand the inner workings.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp_query repeating blocks’ is closed to new replies.