Get current page_id before loop, in functions.php

I’m pretty sure you try to use this conditional tags to early, so they don’t work. From Codex: Warning: You can only use conditional query tags after the posts_selection action hook in WordPress (the wp action hook is the first one through which you can use these conditionals). For themes, this means the conditional tag … Read more

How to alter the query using pre_get_posts hook and is_post_type_archive

You should be using methods of the $query instance instead of the is_* template tags. And are the categories you are trying to filter a custom taxonomy? cat only works on the default category taxonomy: function wpse_178500_event_type_filter( $wp_query ) { if ( ! empty( $_GET[‘event_term’] ) && $wp_query->is_main_query() && $wp_query->get( ‘post_type’ ) === ‘event’ ) … Read more

Edit admin post page

There are functions available in WordPress to add/remove the elements. For instance to remove existing elements on WordPress backend page editor you can use remove_post_type_support function. Below is example usage: <?php add_action( ‘init’, ‘my_remove_post_type_support’, 10 ); function my_remove_post_type_support() { remove_post_type_support( ‘post’, ‘custom-fields’ ); } ?> The above snippet will remove custom-fields box from edit page … Read more

Modifying date filter on admin page for custom post type to link to custom field

Use the pre_get_posts action to override the default query. In the admin, a date query will be the query var m in the format YYYYMM. Assuming your meta dates are stored the same as MySQL dates (YYYY-MM-DD), you can use the following: function wpse_189824_date_meta_query( $wp_query ) { if ( is_admin() && $wp_query->is_main_query() && $wp_query->get( ‘post_type’ … Read more