Created
February 16, 2023 16:37
-
-
Save nfsarmento/6cb8fe9958c0e7f49643e628450f16db to your computer and use it in GitHub Desktop.
Show posts with and without meta_key and order them the ones with meta_key on the top
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'projects', | |
'posts_per_page' => 9, | |
'post_status' => 'publish', | |
'meta_query' => array( | |
'relation' => 'OR', | |
array( | |
'key' => 'featured-checkbox', | |
'value' => 'yes', | |
'compare' => 'EXISTS' | |
), | |
array( | |
'key' => 'featured-checkbox', | |
'compare' => 'NOT EXISTS' | |
) | |
), | |
'orderby' => 'meta_value_num title', | |
'order' => 'ASC', | |
); | |
$featured = new WP_Query($args); | |
if ($featured->have_posts()): while($featured->have_posts()): $featured->the_post(); ?> | |
<div class="c-image"><?php the_post_thumbnail('large'); ?></div> | |
<div class="cstext"> | |
<article> | |
<h2><?php the_title(); ?></h2> | |
<?php the_content(); ?> | |
<a href="<?php echo get_permalink(); ?>" class="readmore">Learn More</a> | |
</article> | |
</div> | |
<?php | |
endwhile; | |
else: 'No Content Added'; | |
endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment