New answers tagged

0

I ended up using a simple meta_query: $args = [ 'post_status' => 'publish', 'post_type' => $post_type, 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'my_acf_field', 'value' => $search_term,...


0

I've found the solution by myself. In brief: use 'order' => 'DESC' The long story: Since I was doing the first page query via php (standard loop), and instead, the above is done via ajax, passing pagination (thus page 1 is php, the following are ajax), there was a mismatch about the order. I was still retrieving what is seemed to be page 1 posts because ...


1

I'm not sure this will fix it, but maybe try using the current category slug for the $current_category variable, instead of single_cat_title(), like so: $term = get_queried_object(); $current_category = $term->slug; This might help because the category_name parameter in WP_Query, despite its name, should be the term slug. single_cat_title() ...


1

I think I am understanding your correctly...If I'm way off, let me know! // Assuming ideas is an array and you are looking for ideas=>two $query = new WP_Query( array( // You can pass 'any' to post_type, but you get a hold of revisions, attachments, and menu_items. But I am not sure how many Custom Post Types you have ¯\_(ツ)_/¯ '...


0

There category is not stored in the wp_posts but in the wp_terms-table. Please have a look here. There query should probably be more like this one: SELECT YEAR(post_date) FROM wp_posts WHERE post_status = "publish" AND ID IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN ( SELECT term_taxonomy_id FROM wp_term_taxonomy ...


0

Relationship between post and category is not stored in the posts table. You must extend your query for additional tables. By category id: SELECT YEAR(p.post_date) FROM {$wpdb->posts} p JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.id JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE tt.term_id = 4 AND ...


0

This is because the category-relations are not stored within the wp_posts table, but in another table named wp_term_relationships. You have to do some joins to get what you want. This should give you an array of Years with the published posts in this year. $years = $wpdb->get_results("SELECT DISTINCT YEAR($wpdb->posts.post_date) as year, COUNT($...


0

After a weekend of searching, i have a solution ! function custom_posts_join($join){ global $wpdb; $join .= " LEFT JOIN $wpdb->postmeta as pm ON $wpdb->posts.ID = pm.post_id "; return $join; } add_filter( 'posts_join' , 'custom_posts_join'); ...


0

'orderby' => 'post__in', 'post__in' => array(5,6,3,8), You need ACF to pass the ID's in order but that should do it.


0

Finally i had create a taxonomy with name manufacturers and an attribute with the same name. This may caused a confict (i didn't find out more!). So i create an attribute with name brands and i use this for my custom query.


Top 50 recent answers are included