Custom Post Type shows pagination (w/404) or posts_per_page query, but not both

user5477769 reports in the comments of the original post, that the problem has been solved: I was following Custom Post Type UI instructions but it seems it led me astray. Creating a archive-gallery.php with a vanilla Loop, along with removing is_main_query has solved all problems, and the pages now show with 9 posts and correct … Read more

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