• Hey –
    I was hoping there was a hook / filter (or other way short of hacking the core) to allow a user to be able to search or filter by a custom field we have set up. I can handle the SQL, etc, needed for a query – I just don’t know the best way to accomplish this.

    Admins of this installation of WordPress have many posts with a custom field, and would like to search/filter on the Edit Posts view (which lists all of your posts) to more easily find the post they are need to edit.

    This custom field is being filled with a date. This date relates to an event (and there is custom code on the frontend to handle dated posts as events – just looking for pointers on the admin area).

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi nikefido!

    I’m looking for exactly the same thing for event managing, too.
    have you (or anyone else out there) found a solution or approach?

    seems that there isn’t a plugin out there, do we need to hardcode the core?

    this works for pages:

    function custom_pages_query( $query )
    {
    	global $wp, $wpdb;
    
    	if( isset($_GET["meta_key"]) )
    	{
    		$wp->private_query_vars[] = 'meta_key';
    		$query['meta_key'] = $_GET["meta_key"];
    	}
    
    	if( isset($_GET["meta_value"]) )
    	{
    		$wp->private_query_vars[] = 'meta_value';
    		$query['meta_value'] = $_GET["meta_value"];
    	}
    
    	if( isset($_GET["post_parent"]) )
    	{
    		$post_parent = $_GET["post_parent"];
    		$wp->private_query_vars[] = 'post_parent';
    
    		if( !is_numeric($post_parent) )
    		{
    			$post_parent = $wpdb->get_var( $wpdb->prepare("SELECT <code>ID</code> FROM $wpdb->posts WHERE <code>post_name</code>='%s' AND <code>post_type</code>='page' AND <code>post_status</code>='publish'"), $post_parent);
    
    			if( NULL === $post_parent )
    				$post_parent = "";
    		}
    
    		$query['post_parent'] = $post_parent;
    	}
    
    	return $query;
    }
    add_filter('manage_pages_query', 'custom_pages_query');

    this is for the edit pages screen. i haven’t looked into edit posts screen much, but the situation is a bit different there since the posts are displayed with post_rows() function, which calls ‘&$wp_query->posts’ to get the list of posts.

    so you would have to modify wp_query when on edit.php screen within wp-admin to add custom stuff.

    i’ll look into it when i find time…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘edit posts screen – sort or search by custom field?’ is closed to new replies.