Wordpress Query_Posts Combine - wordpress

I have the Wordpress theme called Clipper with Flatter as the child theme.
The theme uses query_output to output results in the homepage. My intention is to sort by custom fields, 'clr_up_vote'. However, this caused the outputs to be reduced to only posts with 'clr_up_vote' data and hid the rest.
I initially set out to fix by having two queries in index.php,
$ordered_posts = query_posts(array(
'post_type' => APP_POST_TYPE
, 'ignore_sticky_posts' => 1
, 'paged' => $page
, 'posts_per_page' => 10
, 'offset' => $offset
,'meta_key' => 'clpr_votes_up',
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'clpr_votes_up',
'meta-value' => $value,
'value' => 1,
'compare' => '>='
),
array(
'key' => 'clpr_votes_down',
'value' => '',
'compare' => 'LIKE'
)
)
));
get_template_part('loop', 'coupon');
And,
$unordered_posts = query_posts(array(
'post_type' => APP_POST_TYPE
, 'ignore_sticky_posts' => 0
, 'paged' => $page
, 'posts_per_page' => 10-count($ordered_posts)
, 'offset' => $offset
, 'post__not_in' => $post_ids
));
get_template_part('loop', 'coupon');
But now the pagination doesn't seem to work. I tried to use WP_Query but the theme will only accept query_posts().
Any suggestions will be great. Thanks!

Remove meta query from query posts. Just orderby should be set to meta value and meta key should be set to the clpr_votes_up.
$ordered_posts = query_posts(array(
'post_type' => APP_POST_TYPE
, 'ignore_sticky_posts' => 1
, 'paged' => $page
, 'posts_per_page' => 10
, 'offset' => $offset
,'meta_key' => 'clpr_votes_up',
'orderby' => 'meta_value',
'order' => 'DESC'
));
And if you want all the posts then remove posts_per_page from the query.

Related

order posts by meta query, if featured show first then verified then normal

i want to order posts by meta query, if featured & verified show first then verified and then normal without those meta keys
i tried this code its showing what i need but the order is wrong.
<?php
$sports = get_field('sport', $post_id);
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'meta_key' => 'sport',
'meta_value' => $sports,
'post__not_in' => array ($post->ID),
'meta_query' => array(
'relation' => 'OR',
'featuredmet' => array(
'key' => 'featured',
'compare' => 'EXISTS',
),
'verified_athletemet' => array(
'key' => 'verified_athlete',
'compare' => 'EXISTS',
),
'commitedmet' => array(
'key' => 'commited',
'compare' => 'NOT EXISTS',
),
),
'orderby' => array(
'featuredmet' => 'DESC',
'verified_athletemet' => 'DESC'
)
);
//the query
$relatedPosts = new WP_Query( $args );
if anyone can help me with this super fast that would be great!

Wordpress advanced custom field query giving wrong results

I have the following code. It is supposed to return only the post from 'portfolio' custom post type where the format is 'print', the checkbox for 'welcome_gallery' is checked and the 'market' value is 'italy'. But it returns also other post not matching these key values.
$recent_posts = array(
'post_type' => 'portfolio',
'numberposts' => 8,
'orderby' => 'rand',
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => 'format',
'meta_value' => '%print%',
'compare' => 'LIKE'
),
array(
'meta_key' => 'welcome_gallery',
'meta_value' => '1',
'compare' => '='
),
array(
'meta_key' => 'market',
'meta_value' => '%italy%',
'compare' => 'LIKE'
)
)
);
$the_query = new WP_Query( $recent_posts );
I've tried hard to make it work but it doesn't. Before I get crazy, is there someone who can help me to undestand the reason?
Thanks in advance.

Create a filter in a page template

I am using Realto theme for wordpress I am wondering if I am on the correct path. I need to display properties from a city. So I decide to create a page template to add the location
This are the default arguments but I dont know how to filter the results by city
$args = array(
'numberposts' => '',
'posts_per_page' => $posts_per_page,
'offset' => 0,
'cat' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'property',
'post_mime_type' => '',
'post_parent' => '',
'paged' => $paged,
'post_status' => 'publish'
);
I tried adding
'locations' => 'MYCITY'
but it didnt work
This is an example of the search results when I search by city, so I am basing my arguments on this.
/?post_type=property&search_keyword=&locations=MYCITY&property_type=proyectos&beds=&baths=&status=&min-price=&max-price=
I assume that locations is a custom field? Maybe this works:
<?php
$args = array(
'post_type' => 'property',
'meta_key' => 'locations',
'meta_value' => 'MYCITY'
);
?>
Visit http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters for more details.

wp_query on 2 post types, one having custom field for further filtering

This is my first question on here; I have hunted around for an answer but if it is out there already apologies.
I am using wp_query() to fetch both 'posts' and a custom post type called 'reviews'. However the custom post type has a sub type and I need to filter out all but one of these sub types just for reviews in the same query!
This is where I got to:
$type = array( 'post', 'review' );
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 20,
'paged' => $paged,
'meta_query' => array( // I need to filter the review post type further by subtype
array(
'key' => 'subtype',
'value' => 'review'
),
),
'orderby' => 'post_date', // Order by date
'order' => 'DESC',
);
Obviously, when I run this the default post type is not listed as it doesnt have the subtype custom field. How can I only apply this filter (meta_query) to the custom post type in this query and not have it apply to the default post type 'post'?
Thanks in advanced,
Kris...
UPDATE:
OK, I have tried this but with no success - any ideas?
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 20,
'paged' => $paged,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'subtype',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'subtype',
'value' => 'review',
),
),
'orderby' => 'post_date', // Order by date
'order' => 'DESC',
);
This will check the 'subtype' only if it exists in the post (not tested)
$type = array( 'post', 'review' );
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 20,
'paged' => $paged,
'meta_query' => array(
'relation' => AND,
array(
'key' => 'subtype',
'compare' => 'EXISTS'
),
array(
'key' => 'subtype',
'value' => 'review'
),
),
'orderby' => 'post_date', // Order by date
'order' => 'DESC',
);

Wordpress - Filter by Taxonomy

Something weird happening in my query and can't see what's wrong
I am passing the variable THEME from a select list.
THe theme is pulled from the taxonomy THEME
so my code looks like
$thetheme = $_GET['theme'];`
$thetheme is correctly passed from URL
then
$args2 = array(
'tax_query' => array(
array(
'taxonomy' => 'theme',
'field' => 'slug',
'terms' => $thetheme
)
),
'post_type' => array( 'post', 'dvd' ),
'cat' => '31',
'paged' => $paged,
'posts_per_page' => $listitems,
'order' => 'DESC',
'orderby' => 'date',
'query' => $wp_query
);`
The query is working only on some Post, not all of them, and cant understand why.
If I select a post with the Theme "Adventure" for example, it will pull the correct amount of post.
But an other post, in the same category with a different theme, will not be displayed.
This is puzzling me....
HElP!
thx
Don't think you need here to run complete taxonomy query... try this =)
$args2 = array(
'theme' => $thetheme,
'post_type' => array( 'post', 'dvd' ),
'cat' => '31',
'paged' => $paged,
'posts_per_page' => $listitems,
'order' => 'DESC',
'orderby' => 'date',
'query' => $wp_query
);

Resources