Getting wrong relationship value in $args in wp_Query?
add : $inner_arrays[‘relation’] = ‘OR’; and then query will be like : $args = array( ‘post_type’ => ‘products’, ‘post_status’=> ‘publish’, ‘meta_query’ => $inner_arrays ); this works …. 🙂
add : $inner_arrays[‘relation’] = ‘OR’; and then query will be like : $args = array( ‘post_type’ => ‘products’, ‘post_status’=> ‘publish’, ‘meta_query’ => $inner_arrays ); this works …. 🙂
You can accomplish this with multiple meta queries. $query->set( ‘meta_query’, [ ‘relation’ => ‘OR’, ‘wpcf-start-date’ => [ ‘key’ => ‘wpcf-start-date’, ‘compare’ => ‘EXISTS’, ], ‘no-start-date’ => [ ‘key’ => ‘wpcf-start-date’, ‘compare’ => ‘NOT EXISTS’ ], ] ); $query->set( ‘orderby’, ‘wpcf-start-date’ ); $query->set( ‘order’, ‘ASC’ ); This will tell WP to create a query that will … Read more
I would duplicate the coordinates of the posts in a separate table (post_id, lat, lon), with an index on (lat, lon). With all the joins and the casts I doubt the database can use an efficient index with your query. I once wrote an answer to a similar question using this approach.
Have you tried using get_posts() instead? //#get access to post settings global $post; //#set parameters for extra loop $args = array( ‘post_type’ => ‘mycustomtype’, ‘posts_per_page’ => 12, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); //#get posts $customPosts = get_posts($args); //#loop through them foreach($customPosts as $post) { //#set all the loop functions to … Read more
Did you try this? function sort_query($query) if ($query->is_tax() && $query->is_main_query()){ echo $query->query_vars[‘taxonomy’]; $query->set( ‘orderby’, ‘post_title’ ); $query->set( ‘order’, ‘ASC’ ); //do other stuff } } add_action(‘pre_get_posts’, ‘sort_query’); Happy Coding, Kuchenundkakao
You might want to check out the query improvements in WP 4.2 for ‘orderby’ and ‘meta_query’. Details are on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query. Try to name your meta_query clauses, then order by them. Following code is untested: $query = array( ‘order’ => ‘DESC’, ‘meta_query’ => array( ‘relation’ => ‘OR’, ‘cat1-clause’ => array( ‘key’ => ‘cat1’, ‘type’ => ‘numeric’ … Read more
You should first read (emphasis mine): The sites in a multisite network are separate, very like the separate blogs at WordPress.com. They are not interconnected like things in other kinds of networks (even though plugins can create various kinds of interconnections between the sites). If you plan on creating sites that are strongly interconnected, that … Read more
Since wordpress multisite uses different tables for all blogs, it is very inefficient to get all recent articles of all blogs (content aggregation) on display time since you have to query all blogs, sort the articles by date and display the ammount you need. Plugins like WordPress Post Indexer (https://premium.wpmudev.org/project/post-indexer) additional write all posts into … Read more
These meta queries are going to be expensive, and figuring out the answer and caching it is a poor solution, so why not go to the root of the problem and adjust the data structure? Your core data type is the restaurant, and you want to filter/query so that means taxonomies, so why not have … Read more
Don’t limit the field, instead, limit the index, e.g. ALTER TABLE wp_postmeta ADD key(meta_value(100)) This limits the index to the first hundred bytes of meta_value. You’ll probably want an index on post_id, meta_key, meta_value for joins. How much of meta_key and meta_value is required depends on your data, for example ALTER TABLE wp_postmeta ADD key(post_id, … Read more