Wordpress - Filter by Taxonomy - wordpress

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
);

Related

WordPress multiple tax_query with multiple terms not working

I am tired to get posts using this multiple tax_query but not working at all. Can anyone fix this problem please? If anyone can fix the problem, I will grateful to him/her forever.
This query get nothing. My query is exactly look like -
$args = array(
'posts_per_page' => 18,
'post_type' => 'post',
'post_status' => 'publish',
'tax_query' => array (
'relation' => 'AND',
array (
'taxonomy' => 'taxonomy-1',
'terms' => array( 2024 ),
'field' => 'term_id',
),
array (
'taxonomy' => 'taxonomy-2',
'terms' => array( 2025, 217 ),
'field' => 'term_id',
),
),
);
$posts = get_posts( $args );

WP_Query multiple post type and taxonomies

I would like to get results from two post types,
1) Post, only show 'business' kicker
2) local-news, show all kickers
I've so far:
$args=array(
'cat' => $my_category_id,
'post_status' => 'publish',
'posts_per_page' => 5,
'post_type' => array('post', 'local-news'),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'postkicker',
'term' => 'business'
),
array(
'taxonomy' => 'impactkicker',
),
),
'orderby' => 'date',
'order' => 'DESC'
);
Currently is not showing both post types, any suggestions? Thanks in advance
You need to make sure you've connected your cpt local-news to category taxonomy as well, because you are trying to select by this taxonomy. Here's extensively commented approach which will do what you need i guess. At least if I got your idea clearly. You can change tax_query main relation to OR instead of AND to output items if they don't have category set as well.
$args = array(
// 'cat' => $my_category_id, // better replace it with category in tax_query, see below.
'post_status' => 'publish',
'posts_per_page' => 5,
'post_type' => array( 'post', 'local-news' ),
'tax_query' => array(
'relation' => 'AND', // we set it to AND because we want all posts of this category i guess.
array(
'taxonomy' => 'category',
'term' => $my_category_id,
'field' => 'term_id',
'operator' => 'IN', // just to be more explicit.
),
array( // we create nested sub queries which will filter by other 2 taxonomies, which in turn has OR relation.
'relation' => 'OR',
array(
'taxonomy' => 'postkicker',
'field' => 'slug', // by default it's term_id and you are passing in a slug so set it explicitly.
'term' => 'business',
'operator' => 'IN', // just to be more explicit.
),
array(
'taxonomy' => 'impactkicker',
'field' => 'slug', // set these or not add rule for taxonomy at all.
'term' => 'your-term-slug', // same here.
'operator' => 'IN', // it's a default value, but ou can set 'EXISTS' if you need to check if whatever term of such taxonomy is assigned.
),
),
),
'orderby' => 'date',
'order' => 'DESC',
);

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.

Show Wordpress posts before today

I try to show posts before today in DESC order in Wordpress.
I got this:
<?php query_posts( array( 'cat' => '2186', 'paged' => get_query_var('paged'), 'order' => 'DESC', 'before' => 'strtotime("now")' ) ); ?>
I know I should use the before parameter if I refer to the Wordpress documentation.
Actually, this code doesn't work. What should I try?
Try this, works, and it's easy to modify:
$args = array (
'cat' => '2186',
'paged' => get_query_var('paged'),
'order' => 'DESC',
'paged' => $paged,
'date_query' => array(
array(
'before' => array(
'year' => date('Y'),
'month' => date('m'),
'day' => date('d')
),
'inclusive' => true,
),
),
);
query_posts($args);

Wordpress Query_Posts Combine

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.

Resources