[wp-hackers] Filter wp-admin posts view based on post metadata
Christopher Ross
cross at thisismyurl.com
Sun Sep 19 19:57:32 UTC 2010
Ryan, not directly but you could always add it as a custom search in your functions file.
I'm sure others here can improve on this code but here's a basic custom search for you.
add_action('admin_menu', 'cr_custom_search');
function cr_custom_search() {
add_posts_page('Custom Search', 'Custom Search', 10,'cr_custom_search.php', 'cr_custom_search_page');
}
function cr_custom_search_page() {
echo "<ol>";
global $wpdb;
$metavalue = ""; // whatever you're searching for
$posts = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_value='".$metavalue."'");
foreach ($posts as $post) {
$postdetails = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE ID='". $post->post_id."'");
$id = $postdetails[0]->ID;
$title = $postdetails[0]->post_title;
echo "<li><a href='post.php?post=".$id."&action=edit'>".$title."</a></li>";
}
echo "</ol>";
}
On 2010-09-18, at 7:37 PM, Ryan Bilesky wrote:
> I am wondering if anyone is aware of a way to filter the posts listed in
> wp-admin based on metadata. I have one bit of metadata I would like to see
> only posts where that is equal to a certain value. I did try using the post
> search. I tried just searching for the metadata value and even tried key =
> value as a search term but that search apparently does not search across
> metadata.
>
> Anyone know how to accomplish this?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
__
Christopher Ross
Toronto 1 (416) 840-5828
Fredericton 1 (506) 474-2708
New Orleans 1 (504) 322 3485
http://christopherross.ca
http://www.thisismyurl.com
More information about the wp-hackers
mailing list