How to query all posts of a specific category, and any other category combination
How to query all posts of a specific category, and any other category combination
How to query all posts of a specific category, and any other category combination
The integral part is using a date_query in a custom WP_Query to fetch the adjacent posts according to the parameters passed to it. Here is an idea coming from a plugin I’m busy with To accomplish what you need, you’ll need the following The current post object to get the post_date and ID The categories … Read more
Try this: add_action( ‘template_redirect’, ‘my_test_if_archive’ ); function my_test_if_archive() { global $wp_query; $qv = array_keys( $wp_query->query ); $archives = array(‘year’, ‘monthnum’, ‘day’, ‘w’, ‘m’, ‘author’, ‘post_type’); $is_archive = ! empty( array_intersect( $qv, $archives ) ); $is_tax = ! empty( $wp_query->tax_query->queries ); if ( $is_archive || $is_tax ) { // this is an archive } }
You can probably do something like this. It’s probably less efficient, but should find all descendants of a given page rather than just direct children. function find_descendants($post_id) { $descendant_ids = array(); $pages = get_pages(“child_of=$post_id”); foreach ($pages as $page) { array_push($descendant_ids, $page->ID); } return $descendant_ids; } function SearchFilter($query) { if ($query->is_search) { $query->set ( ‘post__in’, find_descendants(21) … Read more
If I understand you well, you can do that with add_rewrite_rule(); function to map the url to specific query variables. https://codex.wordpress.org/Rewrite_API/add_rewrite_rule function myfunc_rewrite_rules() { add_rewrite_rule(‘user/?([^/]*)’, ‘index.php?pagename=user&username=$matches[1]’, ‘top’); } function myfunc_username_query_vars($vars) { $vars[] = ‘username’; return $vars; } add_action(‘init’, ‘myfunc_rewrite_rules’); //add query vars (username) to wordpress add_filter(‘query_vars’, ‘myfunc_username_query_vars’); function myfunc_display() { $userpage = get_query_var(‘pagename’); $username = … Read more
I know this is an old question, but I thought I’d post the answer in case anybody else is facing the same problem. functions.php: function add_cond_to_where( $where ) { //Replace showings_$ with repeater_slug_$ $where = str_replace(“meta_key = ‘showings_$”, “meta_key LIKE ‘showings_%”, $where); return $where; } add_filter(‘posts_where’, ‘add_cond_to_where’); Query: //Replace showings_$ with repeater_slug_$ //Replace _discounts with … Read more
I if were you, I’d have two options in my mind. Both hinge on the fact thsi is an inherently expensive computation and no mysql trickery will reduce the load with the data you have. So Option 1, do it the expensive way and store the data for a rainy day You’re going to have … Read more
To clear up some confusion in previous answers, pre_get_posts isn’t a filter so you don’t need to return anything. Your only problem that I see is the if: if ( !is_search() && !in_array( get_post_type(), $post_types ) ) return; Basically get_post_type() is going to return false during pre_get_posts because the global $post hasn’t been set yet … Read more
It sounds like you’re looking for the get_terms() function that’s a wrapper for WP_Term_Query. There you can e.g. use the name__like, description__like or search parameters. Example: Here’s what kind of WHERE query they generate: ‘name__like’ => ‘hout’ >>> (t.name LIKE ‘%hout%’) ‘description__like’ => ‘hout’ >>> tt.description LIKE ‘%hout%’ ‘search’ => ‘hout’ >>> (t.name LIKE ‘%hout%’) … Read more
The issue is you are overriding the entire tax_query. When you go to the UK category archive, tax query is set to have the same thing you have for International, but you are nuking the current query. Here is the solution: … $tax_query = $query->get(‘tax_query’); $tax_query[‘relation’] = ‘OR’; // puts the item at the beginning … Read more