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

Which filter/action should I use to serve content for “virtual” files

I think the earliest actions you can hook are muplugins_loaded and plugins_loaded. muplugins_loaded will only fire for Must Use Plugins. Some plugins_loaded pseudo-code: add_action( ‘plugins_loaded’, ‘wpd_plugin_routes’ ); function wpd_plugin_routes() { if( is_a_virtual_file() ){ serve_file(); exit; } } If you want the full WordPress environment, plugins, theme, and authenticated user, right before WordPress parses the request, … Read more

Filter WooCommerce archive pages by an additional category

you need to add your topic to query_vars. function so306156_add_query_vars_filter($vars) { $vars[] = “topic”; return $vars; } add_filter(‘query_vars’, ‘so306156_add_query_vars_filter’); and then, in pre_get_posts, you check for that var and act accordingly: function so306156_manipulate_main_query($wp_query) { if (function_exists(‘is_woocommerce’) && !is_admin()) : if ($wp_query->is_main_query() && is_woocommerce()) { if (isset($wp_query->query_vars[‘topic’])) { $tax_query = $query->get(‘tax_query’); $tax_query[] = [ ‘taxonomy’ => … Read more

Compare meta key to current date in pre get post

What you’re trying isn’t possible with WP_Query. The reason is that because you have only stored the duration, it’s not possible to tell whether a post has expired until you know the publication date and the duration time and add them together. That’s what this does: $expire = get_field( ‘status_time_duration’ ) + get_the_time( ‘U’ ); … Read more

How to use pre_get_posts

pre_get_posts happens just before a WP_Query needs to go to the database to grab stuff. Since every page has a main query, that can be changed. Does it go in the search template? No! By the time templates are loaded, the main query has already decided what to grab and gone to the database. Newcomers … Read more

Can a link in WordPress contain a query string that is picked up as $_POST

Looking at the pre_get_posts hook, the problem becomes apparent, the $Format variable is being pulled out of thin air: function get_all_terms($query) { if(empty($Format)) $Format=”test 1″; echo $Format; This variable is undefined, you cannot declare a variable in one file then use it in in other places like this. To do that you have to declare … Read more

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