Exclude page by title for non admins

Get the page by its title, then use its ID: add_action(‘pre_get_posts’, ‘exclude_pages’); function exclude_pages($query) { if(! is_admin()) return $query; global $pagenow; if (‘edit.php’ === $pagenow && (get_query_var(‘post_type’) && ‘page’ === get_query_var(‘post_type’))) { // Get the page by its title, … $page = get_page_by_title(‘TITLE_HERE’); // then use its ID $query->set(‘post__not_in’, array($page->ID)); } return $query; } References: … Read more

Exclude post type with pre_get_posts?

I found a solution to this myself. It returns the default post type posts instead of excluding the custom post type which is fine for my needs. function my_breakfast_query ( $query ) { // not an admin page and is the main query if (!is_admin() && $query->is_main_query()){ if (is_tax( ‘food’, ‘breakfast’ )){ $tax_query = array( … Read more

Why query by specific date with variables doesn’t return same result that with harcoded integers?

I believe your problem is that you are not casting the variables over into integers. You should give this a try: $query->set(‘date_query’, array( array( ‘year’ => (int)$dies[‘year’], ‘month’ => (int)$dies[‘mon’], ‘day’ => (int)$dies[‘mday’], ), )); or if you would like, before you even set up the arguments for the query, you could do something along … Read more

pre_get_posts with multiple queries

You need to have two queries, one handling the listings, the other handling the map. Since you need pagination for the listings, I’d suggest you use pre_get_posts for that query, so that you can use WordPress’ default pagination out of the box. For the map, create a new WP_Query in your archive template: $args = … Read more

Menu disappears when meta_key changed [closed]

if ( $query->is_main_query() && $query->is_singular ) { return; } This is the wrong way around – it’s actually ensuring that the query is being modified on everything except the main query, which is why it’s affecting the menus (which are also built using queries). You need to change it to if ( !$query->is_main_query() && !$query->is_singular … Read more

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