Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu

I was having the exact same problem on an archive page of a custom post type with a needless extra query; for pagination reasons. Searching for the same solution I found this post on Stack Overflow https://stackoverflow.com/questions/21303743/new-wp-query-or-pre-get-posts-to-view-all-posts-for-custom-post-type I had a play and added this line of code into the function. if( ! $query->is_post_type_archive()) return; So … Read more

Set a custom number of posts on the first page

The pre_get_posts runs before WP_Query has been setup. Some template tags and conditional functions that rely on WP_Query will not work. you will need to work directly with the query vars, which are passed to the pre_get_posts hook as an argument. See the more information on the following pages: pre_get_posts and using pre_get_posts Try using … Read more

Using $seed on a custom post type for randomly displayed posts

This is untested, but I think it should work. Add the filter in pre_get_posts if it’s your post type archive, otherwise remove it for any queries that follow the post type archive main query. function wpd_add_posts_orderby( $query ){ if( $query->is_post_type_archive(‘your-cpt’) ){ add_filter(‘posts_orderby’, ‘edit_posts_orderby’); } else { remove_filter(‘posts_orderby’, ‘edit_posts_orderby’); } } add_action( ‘pre_get_posts’, ‘wpd_add_posts_orderby’ );

excludeCat function reverses order of blog posts

function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘cat’, ‘-5377’ ); $query->set( ‘orderby’, ‘date’ ); $query->set( ‘order’, ‘DESC’ ); } } add_action( ‘pre_get_posts’, ‘exclude_category’ ); Use ASC or DESC for order. Add code to child themes functions file. Tested and works.

Problem to show custom post type in archive page category wise

You need to check the information that their is in action variable. $action = (isset($_REQUEST[‘ac’])) ? $_REQUEST[‘ac’] : ‘none’; var_dump(“action: “+$action); With this line, you will be able to review it’s content and you will see that you don’t get the correct information. I guess that your dev database is out off synch with your … Read more

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