[wp-hackers] do I need to register custom post_status-es?

Davit Barbakadze jayarjo at gmail.com
Fri Mar 26 11:44:58 UTC 2010


Hi Mike,

Thanks, but I do not actually use or need to use either meta_value or
meta_key. I just can't filter my custom type posts, by custom
post_status fields.

:(

On Wed, Mar 24, 2010 at 9:28 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> Davit:
>
> On Mar 24, 2010, at 7:29 AM, Davit Barbakadze wrote:
>> I'm using the following code to retrieve custom post_type-es:
>>
>> $wp_query = new
>> WP_Query("post_type=event&post_status=$post_status&posts_per_page=15&paged=$paged{$search}");
>>
>> Quoted line resolves for example to:
>> post_type=event&post_status=active&posts_per_page=15&paged=1 (string
>> has been printed out not just made up).
>>
>> Although while I have specific post_status defined, for some
>> reason it does fetch all of the posts with post_type=event, no matter
>> are they marked as active in post_status or - inactive. Not sure what
>> could be the reason. For post_status - trash it filters them as
>> expected. Do I need to register custom post_status-es
>> maybe?
>
> I think these two pages might hold your answers:
>
> --------------------
> http://osdir.com/ml/wordpress-hackers/2010-01/msg00233.html
> --------------------
> "Bear in mind that the wp() call only accept query vars which are specified in the $public_query_vars and $private_query_vars arrays which are part of the WP class and these don't include anything to do with post_meta.
>
> The public_query_vars are those which can be specified in a url and the private_query_vars are the extra ones which can be specified only by code
>
> You will need to extend the list of private_query_vars which it supports to get the post_meta ones passed through"
>
>
> --------------------
> http://wordpress.org/support/topic/281165?replies=3
> --------------------
> 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');
>
> HTH
>
> -Mike
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Davit Barbakadze


More information about the wp-hackers mailing list