The Operator “NOT IN” Does Not Work In tax_query

I suspect you need an array for the terms – although I’m not sure why it would work with “IN” and not with “NOT IN”… But I’d try this: function menta_pre_get_posts( $query ) { if ( !is_admin() && $query->is_search() && $query->is_main_query() ) { $term = get_term_by(‘slug’, get_query_var(‘s’), ‘product_tag’); if ( $term && !is_wp_error( $term ) … Read more

Exclude comments from a WP_Query object?

Did you actually find a case where there are any real comments in the wp-query object after running a normal query? If you examine the code in class-wp-query.php, you should find that the comments field only is populated with comments when a “comments-feed” is being queried for. In normal operation, comments are not retrieved by … Read more

$wp_query initiation?

User Rarst has a very famous answer where he lays out the load process. Looking at this graph whenever wp-blog-header.php gets loaded it calls function wp() which sets up many of WordPress globals like $post and $wp_query. ( Secondary Reference by User Gmazzap ) That’s the technical side of things but it looks like the … Read more

Query Custom Post Type taxonomy type based on page

To make that more efficient, instead of arguing the current page slug, you just place the current slug as the tax_query’s terms value. Something like: global $post; $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘books’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘book_category’, ‘field’ => ‘slug’, ‘terms’ => $post->post_name, // which’d be … Read more

How to stop wordpress to make the default query?

Stop WordPress to run main query is hard: you have to dig inside the deep heart of WordPress. WordPress frontend workflow: wp-blog-header.php call the function wp() wp() function creates an instance of wp class, and call main() method on it main() method code: public function main($query_args=””) { $this->init(); $this->parse_request($query_args); // build query vars starting from … Read more

How to add multiple images to a custom post type single post?

Thanks for the suggestions, guys. I did some more research, and found this – https://wordpress.org/plugins/attachments/ It’s a great plugin that lets you attach images to the post without inserting them in the post and the images can be easily sorted with ajax, it’s also quite modifiable and just what I needed, and works on custom … Read more

Exclude categories from search query

You can use pre_get_posts action to exclude categories from search query. function wcs_exclude_category_search( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_search ) { $query->set( ‘cat’, ‘-22, -21’ ); } } add_action( ‘pre_get_posts’, ‘wcs_exclude_category_search’, 1 ); You should paste this code in your theme’s functions.php file.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)