In Product Category archives how to show Posts having same/similar prod_cat slug structure?

Here I’ve written a function for you- function the_dramatist_get_product_cat_posts( $args = array() ) { $default_args = array( ‘taxonomy’ => ‘product_cat’, ‘get_post_type’ => ‘post’ ); $t = array(); $param = wp_parse_args($args, $default_args); $prod_terms = get_the_terms(get_the_ID(), $param[‘taxonomy’]); foreach ($prod_terms as $prod_term ) { $t[] = $prod_term->term_id; } $posts = get_posts(array( ‘post_type’ => $param[‘get_post_type’], ‘numberposts’ => -1, ‘tax_query’ … Read more

query_posts based on a meta_key

This answer is pretty covering for this I think: $args = array( ‘post_type’ => ‘brand’, ‘posts_per_page’ => 999, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘wpcf-sorter’, ‘compare’ => ‘NOT EXISTS’, ), array( ‘key’ => ‘wpcf-sorter’, ‘compare’ => ‘EXISTS’, ), ), ‘orderby’ => array( ‘meta_value’ => ‘DESC’, ‘date’ => ‘DESC’ ), ); That should … Read more

My query keeps looping infinitely ! how to stop it?

Like Tom commented, your code is hard to read. You can look at the code snippet below as a suggestion based on what your code. function get_posts_by_admin_role( ) { if ( is_admin() && !is_front_page() && !is_singular() && !is_archive() ) { $args = array( ‘role’ => ‘administrator’, ‘orderby’ => ‘post_count’, ‘order’ => ‘ASC’, ‘count_total’ => false … Read more

How to create page that lists tags by initial letter?

First Question’s Answer: For filtering based on your terms first letter you need to filter the query, which you can do with the terms_clauses hook. By putting the below code block in your theme’s functions.php you can do that- function the_dramatist_filter_term_clauses( $clauses ) { remove_filter(‘term_clauses’,’the_dramatist_filter_term_clauses’); $pattern = ‘|(name LIKE )\’%(.+%)\’|’; $clauses[‘where’] = preg_replace($pattern,’$1 \’$2\”,$clauses[‘where’]); return … Read more

A very strange problem with search query

By default, WordPress searches by keyword. To use a custom query variable for search, you would have to register the custom query variable using query_vars function wpse250276_register_query_vars( $vars ) { $vars[] = ‘ait-locations’; return $vars; } add_filter( ‘query_vars’, ‘wpse250276_register_query_vars’ ); Then you need to use pre_get_posts to alter search query and include your custom taxonomy … Read more