Ecommerce Shopify WordPress Discussion

Sorting Posts by Custom Field is not working properly in WordPress

I have WordPress posts and I have Boolean Advanced Custom Field for each, which changes the status of being featured for each university post. So when outputting them, I want to show the featured ones (more clearly, the ones which have the featured field set to true) first. But when I'm doing it, WordPress is showing me 8 posts, but not 10 (as I wrote), even though I have enough posts. What can be causing the issue? $args = array( 'post_type' => 'university', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => 'featured', 'orderby' => 'meta_value', 'order' => 'DESC' ); I tried browsing and asking ChatGPT, but I didn't find any working solution yet.
In a WordPress query, if you order by a meta_value, posts that do not have this meta_value set will be excluded from the results. Even if you set the default value of a boolean custom field to false, this value is not set on a post until you update that post. So, you have to open all posts and save a value (true or false) for this meta_value, or run a script to set this value on all posts where you haven't yet set a value.

January 23, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.