Query posts by specific word on title

The answer to this question is here. The full credit of the answer to my question goes for the author of the answer birgire. All I had to do was slightly change is plugin “Support for post name like in WP_Query” turning it into a function like this: add_filter( ‘posts_where’, ‘title_like_posts_where’, 10, 2 ); function … Read more

Creating a custom search for a specific post type

To enable search on a custom post type archive, I use the pre_get_posts hook. Add this code to your theme functions.php file. Here is an example of enabling search on a post type called “resource”: // Enable resource search add_action(‘pre_get_posts’,’pk_enable_resource_search’, 1000); function pk_enable_resource_search( $query ) { if ( $query->is_archive(‘resource’) && $query->is_main_query() && ! is_admin() ) … Read more

Rewrite rule to prettify two $_GET variables while in a new endpoint from a page

I think you are using endpoints incorrectly. When a endopoint is created, a new rewrite rule is created using a query var with the same name of the endpoint; its value is taken from the string that follows the endpoint definition. So, if you register “my-endpoint” and build this URL: /page-slug/my-endpoint/123/some-string The endpoint is passed … Read more

Multiple Loops Inside a Function

the permalink and post title won’t be available until after you’ve run the query. the following should return the last 3 posts from the designated category. the same post is being displayed 3 times because it doesn’t look like you’re setting the permalink or post title from within “the loop” if (!function_exists(‘get_posts_menus’)): function get_posts_menus($category_name, $count) … Read more

Query with custom taxonomy not working

The solution is to use: ‘taxonomy’ => ‘meal’, ‘field’ => ‘slug’, ‘terms’ => ‘breakfast’ The taxonomy and terms are obvious, but why does field have to be slug? When you add taxonomy parameters, you can specify what ‘breakfast’ is– via the field. It could be the term’s ID, the full name, or slug. See the … Read more

Complex date range with WP_Query and BETWEEN

It’s a little hard to think in meta_query code for complicated case like this and without access to data. 🙂 What you have working can be expressed as two following conditions: start_date BETWEEN event_begin and event_end end_date BETWEEN event_begin and event_end Your first case with both in between seems irrelevant, since these two will catch … Read more

Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?

Boohoo why did I start a bounty for that 😉 The answer is pretty simple – add ‘type’ => ‘numeric’ to the meta query. array(5) { [“posts_per_page”]=> int(6) [“orderby”]=> array(2) { [“uss_product_price”]=> string(4) “DESC” [“uss_product_weight”]=> string(4) “DESC” } [“meta_query”]=> array(3) { [“relation”]=> string(3) “AND” [“sortprimary_clause”]=> array(3) { [“key”]=> string(17) “uss_product_price” [“compare”]=> string(6) “EXISTS” [“type”]=> string(7) … Read more