Support

Account

Home Forums Backend Issues (wp-admin) Query to only show featured posts

Solved

Query to only show featured posts

  • trying to get a wp query to only show the featured posts and limit them to 10, pretty sure I have done something wrong, it has been many years since I have had to to any kind of programming

    trying to limit what is shown to only 10 items and only show the featured ones, using the ACF true/false field, we started with this:

    function get_staff( ){
    // Return the staff
    return get_posts(array(
    “posts_per_page” => 10,
    “post_type” => “staff”,
    “post_status” => “publish”,
    ));

    which works, but now we want to have more staff entries but only show the 10 featured ones, so I added the field, marked some as being featured, and the rest as not, change the code to this

    function get_staff( ){
    // Return the staff
    return get_posts(array(
    “key” => “featured”,
    “compare” => “=”,
    “value” => “1”,
    “posts_per_page” => 10,
    “post_type” => “staff”,
    “post_status” => “publish”,
    ));

    and it is still showing the ones which were not marked as featured, how do I get this to work and only show the featured ones?

    thanks

  • did a bit of reading on the WP site and figured it out

    function get_staff( ){
    // Return the staff
    return get_posts(array(
    “post_type” => “staff”,
    “posts_per_page” => 10,
    “post_status” => “publish”,
    ‘meta_query’ => array(
    array(
    “key” => “featured”,
    “value” => “1”,
    )
    )
    ));
    }

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

The topic ‘Query to only show featured posts’ is closed to new replies.