Support

Account

Home Forums General Issues Showing only post with certain field in query args?

Solving

Showing only post with certain field in query args?

  • Hey peeps

    I’m using genesis and genesis_custom_loop to show some post on the home page of a client site…all working well

    but how can I only show posts that have say a ACF of say on_special (value of yes)

    tried the meta key and value but it shows no results…any thoughts?

    $args1 = (array(
    ‘post_type’ => ‘destination’,
    ‘posts_per_page’ => 3,
    ‘no_found_rows’ => true,
    ‘meta_key’ => ‘on_special’,
    ‘meta_value’ => ‘yes’,
    ));

  • is ‘on_special’ a true/false field? If it is then is stores a value of 0 or 1. Yes and No are just the labels. Try using 'meta_value' => '1'

  • Hi John, thanks for the quick reply

    It’s actually just a checkbox (check to enable specials)

    is there a meta_value when a checkbox is checked?

    otherwise I can change the field type.

  • I change the specials field to a true/false field

    and added the meta_value as suggested above

    but still show no posts…

    🙁

  • a “checkbox” field stores an array of values, you would need to use a ‘meta_query’ so that you can compare using LIKE "Yes" or something along those lines. If you changed the field type you’ll also need to edit all of the posts to update the values.

    What function are you using the query args in? Are you using WP_Query or something else?

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

The topic ‘Showing only post with certain field in query args?’ is closed to new replies.