Skip to content

Instantly share code, notes, and snippets.

<?php
add_action( 'pre_get_posts', 'the_dramatist_filter_pre_get_posts' );
function the_dramatist_filter_pre_get_posts( $query ) {
if( is_admin() && $query->is_main_query() && in_array( $query->get('post_type'), array('shop_order') ) ) {
add_filter( 'posts_join', 'the_dramatist_filter_pre_get_posts_query_join' );
add_filter( 'posts_where', 'the_dramatist_filter_pre_get_posts_filter_date' );
}
}
@mariusvetrici
mariusvetrici / Filter Custom Posts by Author in WP-ADmin.php
Last active February 1, 2024 05:37
Need to filter your Custom Post Types (WordPress) by Author in WPAdmin? Here's a handy way to do it by adding a new drop down for filtering
<?php
add_action( 'restrict_manage_posts', 'admin_posts_filter_restrict_manage_posts_by_author' );
/**
* Create the drop down
*
* @return void
*/
function admin_posts_filter_restrict_manage_posts_by_author(){
if (isset($_GET['post_type']) && 'task' == $_GET['post_type']){
wp_dropdown_users( array(
@westonruter
westonruter / filter-post-thumbnail-id.php
Last active January 5, 2023 06:42
How to filter the response for get_post_thumbnail_id()
<?php
/**
* How to filter the value that would be returned by get_post_thumbnail_id()
*/
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) {
// We want to pass the actual _thumbnail_id into the filter, so requires recursion
static $is_recursing = false;
// Only filter if we're not recursing and if it is a post thumbnail ID