[wp-hackers] Function to get posts by meta

Bill Dennen dennen at gmail.com
Tue Aug 3 12:08:04 UTC 2010


Christian,

Could you use this?

http://codex.wordpress.org/Template_Tags/get_posts

$post_type
(string) (optional) The type of post to show. Available options are:
post - Default
page
attachment
any - all post types
Default: post

$meta_key and $meta_value
(string) (optional) Only show posts that contain a meta (custom) field
with this key and value. Both parameters must be defined, or neither
will work.

On Tue, Aug 3, 2010 at 7:56 AM, Christian Gundersson <christian at buro2.se> wrote:
> Hi,
>
> I'm writing a plugin for a client using custom post types and ran across a
> situation where I wanted to retrieve post data from posts that shared the
> same meta data (key and value). I didn't find anything in Wordpress core or
> by searching so I wrote a function for it myself and I'm wondering if it
> would be of any interest to anyone else.
>
> The function, as said, takes a meta key and a meta value as argument and
> then performs a search for posts that has that exact match. The return value
> is an array with the post data.
>
> The code is viewable on github: http://gist.github.com/506224
>
> I have two questions on this though.
>
> 1) Have I done the function properly? (I'm fairly new so I'd like some tips
> and hints to improve my coding skills on Wordpress)
>
> 2) Would this be of any interest for inclusion in Wordpress? And if not, why
> not?
>
> Thanks!
>
> Regards,
> //Christian, Büro 2
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list