Conditional tags returning different results for different areas on a page?

I may have misinterpreted what you are asking here but you don’t need to do this using pre_get_posts(). Instead you could either add this to your functions file: function output_page_type() { global $post; $pagename = $post->post_name; return $pagename; } and then on the relevant page echo output_page_type(); to get the page title. Or you could … Read more

Limiting a filtered query

I noticed that the problem was related that one custom field was a taxonomy, so, as I was using the archive page for that custom post type, I only needed to filter the query looking for the date limits. $fecha_actual = current_time(‘Ymt’); //t regresa el ultimo día del mes $fecha_anterior = date(‘Ymd’, strtotime(“first day of … Read more

admin uploads pre_get_posts not working as expected

Well first off get_current_screen only works in admin area but even in admin can cause problems on some page. Use the $pagenow global variable instead. So now if you want to hide media not uploaded by a contributor this is how I would do it. // Prevents user to see all uploads, only theirs add_action(‘pre_get_posts’,’wpse_users_own_attachments’); … Read more

Using the same WP_Query for shop and widgets in WooCommerce shop

The reasons your pre_get_posts filter does not work on the widget are the condition !$wp_query->is_main_query() makes the filter handle only the main query and nothing else Your special parameter myattr is “self populating” only on the main query but it is not propagating automatically to other queries. To make it work on the widget, the … Read more

Sort posts by meta value with get method

You’re not actually using the $_GET[‘orderby’]-value anywhere. What you’re doing in your code is ordering by the text_date-meta value, always. If you want to order by date by default, and when $_GET[‘orderby’] is set to default orderby-values or if $_GET[‘orderby_meta’] is set, order by those instead you need to do something like this: if (isset($_GET[‘orderby’]){ … Read more

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