Support

Account

Forum Replies Created

  • Just came across this answer and thought it best to point out the the example above would cause issues with an id that has 16 in as it would match 116,161,1216, etc. and so the quotes around the value are important as per the comment.

    So…

    
    $args = array (
        'meta_query' => array(
            array(
                'key' => 'bedrijf', // name of custom field
                'value' => '"16"', // matches exaclty "16", not just 161. This prevents a match for "1234"
                'compare' => 'LIKE'
            )
        )
    );
    
  • The latest update has no fix for this, if you apply it you must disable the check as in the original post.

  • Solved in 5.5.9 update.

  • Scratch that, on closer inspection, the get_field( ‘block_links’ ) isn’t returning a post object but rather a post ID.

    So, my field definition

    
    	register_field_group(array (
    		'id' => 'acf_page-extensions',
    		'title' => 'Page Extensions',
    		'fields' => array (
    			array (
    				'key' => 'field_5800d28886448',
    				'label' => 'Block links',
    				'name' => 'block_links',
    				'type' => 'post_object',
    				'instructions' => 'Select pages to display in link blocks.',
    				'post_type' => array (
    					0 => 'post',
    					1 => 'page',
    				),
    				'taxonomy' => array (
    					0 => 'all',
    				),
    				'allow_null' => 0,
    				'multiple' => 1,
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'page',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'normal',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    

    The retrieval code

    
    $blocks = get_field( "block_links" );
    

    Is returning a post ID rather than the post object.

  • Made some progress on this, using setup_postdata( $post_object ) is a no-no according to the codex. You should always use setup_postdata( $post ) where the var name is “$post” and not anything else.

    See Function Reference/setup postdata

    Switching my example from $blockPost to $post has partially cured the issue although it persists on “Trying to get property of non-object” on the last iteration.

  • After the update, all the custom fields are not returned. The loop iterates correctly but the values are not included ($blockTitle in my code).

    On checking the post where the fields value are entered, the custom fields are no longer being displayed.

  • My field definitions:

    
    register_field_group(array (
    	'id' => 'acf_page-extensions',
    	'title' => 'Page Extensions',
    	'fields' => array (
    		array (
    			'key' => 'field_5800d28886448',
    			'label' => 'Block links',
    			'name' => 'block_links',
    			'type' => 'post_object',
    			'instructions' => 'Select pages to display in link blocks.',
    			'post_type' => array (
    				0 => 'post',
    				1 => 'page',
    			),
    			'taxonomy' => array (
    				0 => 'all',
    			),
    			'allow_null' => 0,
    			'multiple' => 1,
    		),
    		array (
    			'key' => 'field_5805e3f350cf1',
    			'label' => 'Latest Offers',
    			'name' => 'latest_offers',
    			'type' => 'post_object',
    			'instructions' => 'Select the pages you wish to link to as special offers.',
    			'post_type' => array (
    				0 => 'page',
    			),
    			'taxonomy' => array (
    				0 => 'all',
    			),
    			'allow_null' => 0,
    			'multiple' => 1,
    		),
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'page',
    				'order_no' => 0,
    				'group_no' => 0,
    			),
    		),
    	),
    	'options' => array (
    		'position' => 'normal',
    		'layout' => 'default',
    		'hide_on_screen' => array (
    		),
    	),
    	'menu_order' => 0,
    ));
    

    My display code:

    
    $blocks 		= get_field( "block_links" );
    
    foreach ($blocks as $blockPost) {
    
    	setup_postdata( $blockPost );
    
    	$blockTitle = get_field( "block_title", $blockPost->ID );
    	if(empty(trim($blockTitle))) {
    		$blockTitle = $blockPost->post_title;
    	}
    
    ?>
    
    <div class="small-12 medium-6 columns post-block">
    	<div class="img">
    		<h4><a>ID); ?>" class="hvr-sweep-to-right"><?php echo $blockTitle; ?></a></h4>
    	</div>
    </div>
    
    <?php
    	$count++;
    }
    
    wp_reset_postdata();
    
    ?>
    
  • Same here, locked myself out too 🙂

Viewing 8 posts - 1 through 8 (of 8 total)