Support

Account

Home Forums General Issues wp_get_recent_posts where ACF field is null

Solving

wp_get_recent_posts where ACF field is null

  • So I extended the blog to add an ACF repeater field. We have another page where we list the 3 latest posts. To get these posts, I am using:

    	$args = array('numberposts' => '3',
    								'post_status' => array('publish')
    								);
    								
    	$posts = wp_get_recent_posts( $args );

    How can I prevent posts that have the repeater field populated from being returned using this query?

  • Hi @neil

    Did you try looking for false?

    
    'meta_key' => 'repeater_field',
    'meta_value' => 'false',
    

    Let me know!

  • @keithlock I was hopeful, but this does not work. I would expect the query to return null rather than false

  • Hi Neil,

    I received some feedback about my reply… and I stand corrected. Here’s the feedback which should be helpful to you:

    The WP_Query docs feature heaps of ‘meta’ args examples including ’empty’ – https://codex.wordpress.org/Class_Reference/WP_Query

    I believe the meta_query value can be set to ‘NOT EXISTS’.
    Also, a repeater field with 0 rows will be saved with a value of ‘0’, not ‘false’.

    ———-

    My apologies for incorrect info in my original reply.

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

The topic ‘wp_get_recent_posts where ACF field is null’ is closed to new replies.