WPQuery loop not giving expected output

It was a little bit hard to understand the question at first, but… If all you want to do is to sort properties by some custom field, then there’s no need to create custom WP_Queries and all that code you wrote… All you need to do is to add sorting params to the main query … Read more

wordpress query returning unexpected results

First thing first, mind your formatting. Future you thanks you! Second, you’ve just got some weird array sticking around in your $args variable. I believe what you’re looking for is meta_query which takes “an array of arrays” to compare by. Third I believe you’re also looking for posts_per_page, not numberposts. posts_per_page is the record limiting … Read more

return child post if available otherwise parent post

You’d need at least 2 queries for this task, since it’s irregular. For example // collect all child posts $allChildPosts = get_posts([ ‘post_parent__not_in’ => [0], ‘posts_per_page’ => -1, ]); // list child posts and filter one post by parent id $childPosts = []; foreach ($allChildPosts as $post) { $childPosts[$post->post_parent] = $post; } // get all … Read more