URL to Post Archive of Custom Query

Answering my own question seems weird, but here is how I was able to achieve it – function filter_posts_by_id($query) { if ( !is_admin() && is_post_type_archive(‘CPT_NAME’) && $query->is_main_query()) { $post_ids = $_GET[‘post_ids’]; if(!empty($post_ids)) { $pids = explode(‘,’,$_GET[‘post_ids’]); $query->set(‘post__in’, $pids); } } } add_action(‘pre_get_posts’, ‘filter_posts_by_id’); PHP’s predefined variable $_GET[‘parameter’] to get the query string PHP’s explode() to … Read more

WP Query – Search in title or author_name

EDIT : Sorry just read that you need a ‘OR’ in your query. I will update anwser soon. According to your question, you can try this code. // WP_Query arguments $args = array( ‘name’ => ‘test’, ‘author_name’ => ‘test’, ); // The Query $query = new WP_Query( $args ); // The Loop if ( $query->have_posts() … Read more

Custom category page with taxonomy filters

The solution: Add ‘operator’ => ‘AND’, to the tax_query. ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘offer’, ‘field’ => ‘slug’, ‘terms’ => array($offer), ‘operator’ => ‘AND’, ), array( ‘taxonomy’ => ‘network’, ‘field’ => ‘slug’, ‘terms’ => array($network), ‘operator’ => ‘AND’, ),

Show posts by category – category ID not working

Of course it doesn’t work. What examples are using this code? Let’s take a look at Category Parameters of WP_Query There are 5 category parameters: cat (int) – use category id. category_name (string) – use category slug. category__and (array) – use category id. category__in (array) – use category id. category__not_in (array) – use category id. … Read more

Slow Query with more 100 products

So you want only the “first” products having a unique product_cip? I think a direct MySQL Query may be quicker: function get_all_product_in_selected_category($atts){ // Get the category if(!(isset($atts[‘category_id’]) || !is_numeric($atts[‘category_id’])){ return 0; } $catsearched = $atts[‘category_id’]; global $wpdb; $productssql = “SELECT min($wpdb->posts.ID), meta_value FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON … Read more

From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed

To get the username of a user you can use the get_userdata() function. Pass it the users ID $user = get_userdata($user_id); Then the have access to the username or user_login as its called echo $user->user_login; You can read more about this function here: https://codex.wordpress.org/Function_Reference/get_userdata Or if you need to get the user by other information, … Read more