[wp-hackers] do I need to register custom post_status-es?
Davit Barbakadze
jayarjo at gmail.com
Sat Mar 27 19:24:35 UTC 2010
Thanks Mike,
Actually this is something I was looking for, but then you are right
it's not available in wp 2.9.x. Obviously something similar has to be
done in wp < 3.0, but wondering what exactly.
@Tim,
Yes, those are not built in post_status-es, and probably if I not come
to some solution somehow, I will turn to use publish and draft instead
of active/inactive. But making custom post_statuses work can be very
useful later on.
On Fri, Mar 26, 2010 at 11:09 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> Davit,
>
> After sending that email I feared you might confuse the reason I sent the second link. The first link explains that post_status is private and that you (may) need to set it in manage_pages_query. The second link shows you an example manage_pages_query. I wasn't 100% sure of this solution so I offered it up by saying "I think..." assuming it would give you what you need to solve the problem.
>
> Before replying today I decided to track down an actual solution. It seems that information I gave might have been was wrong though I still don't fully understand that area of the code. Sorry for the prior inadvertent misdirection but the best I've been able to tell is that maybe you haven't run register_post_status() in your plugin or theme's functions.php file?, i.e.:
>
> register_post_status('active');
>
> When I run this query without registering the active status I get all posts, regardless of status:
>
> $q = new WP_Query('post_type=post&post_status=active');
>
> After registering I only get the one 'active' post I added for testing.
>
> HTH; let me know if not.
>
> -Mike
> P.S. I tested on a version of wp.30 so maybe it's not what you need for wp2.9...
>
>
> On Mar 26, 2010, at 7:44 AM, Davit Barbakadze wrote:
>
>> 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
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> 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