WordPress custom post type -> query and sort by custom field with multiple values, then published date

You can use the relation = OR in your meta_query args. Something like this:

$args = [  
    'post_type' => 'blogs',
    'post_status' => 'publish',
    'posts_per_page' => 24,
    'meta_query' => array(
        'relation' => 'OR',
        'featured_clause' => array(
            'key' => 'featured_post',
            'value' => 'yes',
            'compare' => '='
        ),
        'not_featured_clause' => array(
            'key' => 'featured_post',
            'value' => 'no',
            'compare' => '='
        )
    ),
    'orderby' => array(
        'featured_clause' => 'DESC',
        'CPT_Images_published-date' => 'DESC'
    ),
    'meta_key' => 'CPT_Images_published-date',
];

$cptQuery = new WP_Query($args);

Note: The code above is just an example. It’s not 100% gonna work with the rest of your code, so try adjusting it according to your needs.

But if you’re going to limit the featured_post = yes to just 3 posts, WP_Query doesn’t directly provide a mechanism to limit results based on meta values. But a way around this is running two separate queries. Something like this:

Query for Featured Posts (max 3)

$featured_args = [
    'post_type' => 'blogs',
    'post_status' => 'publish',
    'posts_per_page' => 3, // Limit to 3 posts
    'meta_query' => [
        [
            'key' => 'featured_post',
            'value' => 'yes',
            'compare' => '='
        ]
    ],
    'orderby' => 'CPT_Images_published-date',
    'order' => 'DESC',
    'meta_key' => 'CPT_Images_published-date'
];

$featured_posts = new WP_Query($featured_args);

Query for Non-Featured Posts

$non_featured_args = [
    'post_type' => 'blogs',
    'post_status' => 'publish',
    'posts_per_page' => 21, // Adjusting for 3 featured posts to maintain total 24
    'meta_query' => [
        [
            'key' => 'featured_post',
            'value' => 'no',
            'compare' => '='
        ]
    ],
    'orderby' => 'CPT_Images_published-date',
    'order' => 'DESC',
    'meta_key' => 'CPT_Images_published-date'
];

$non_featured_posts = new WP_Query($non_featured_args);

Then merge the results in your loop like this:

$all_posts = array_merge($featured_posts->posts, $non_featured_posts->posts);

foreach ($all_posts as $post) {
    setup_postdata($post);
    // your loop content here
}

wp_reset_postdata();

Note: Again the code is just an example for you to use as refference. Please test it out, and adjust to make it work with your current code.

By doing that, you get a maximum of 3 featured posts, then fill up the rest with non-featured posts. This ensures that your front end displays up to 24 posts with the desired prioritization.

I hope this helps!

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino