Forum Replies Created

  • Oke nevermind, I finally got it to work, like i said, solutions often are in a small corner.

    'post_type' => 'nieuws',
                        'posts_per_page' => 1,
                        'orderby' => 'date',
                        'order' => 'DESC',
                        'meta_query' => array(
                                'key'       => 'featured',
                                'compare'   => 'LIKE',
                                'value'     => 1

    I changed the compare from ‘=’ to ‘LIKE’. I don’t understand the reason why ‘=’ doesn’t work and ‘LIKE’ does, but atleast it solved the problem!

    Thanks for the support Enorog!

    Fijne dag verder 🙂

  • That way of putting it in the query from the start is the first thing i tried to tackle this problem when it arose.

    $args = array (
        'post_type' => 'nieuws',
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'DESC',
        'meta_key' => 'featured',
        'meta_compare' => '=',
        'meta_value' => 'featured'    

    I tried changing the meta_value to 1 like in your example, I tried to change the values for the checkbox itself in the admin panel, but some how it just doesn’t want to show any post, even if i set the posts_per_page to -1 just for testing purposes. And this got me looking to other solutions like in my first post. I know there is something wrong with the meta_value bit of the query, I tested if the meta_key on its own works and it does. The solution may well be in a small corner, but I just can’t figure it out hehe…

  • Thank you for your reply, unfortunately with this info i could’t fix the problem. I understand that I’m already in the loop so it works just with the first post. But the situation where i’d like to get to is if the first post doesn’t have the checkbox ‘featured’ activated, it skips to the next post down the line to see if it’s activated there and then output the result. I know of the posts_per_page -1 showing all posts, but i want the latest possible post that has the checkbox featured activated ( only show 1 post). So i guess i need some form of check included in the loop to check for the ‘featured’-value of the checkbox and if a post doesnt have that value it moves to the next post to see if it has and output that post instead.

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