Support » Plugins » Hacks » Stage manager custom post types

  • Hello all,

    I’m working on this plugin which creates 2 custom post types. One for artists and one for events. I use multiple metaboxes to set additional values for the events, such as: start-date, end-date, time and ofcourse you can select the artists for the events. This all works well. But now i am trying to create a list of upcoming events and i need some serious help with creating the query.

    I have one meta_key called _datetime which holds the following data:

        [start_date] => 2010-12-08
        [end_date] => 2010-12-08
        [time] => 12:31

    Now i want to query my custom post type to do the following:
    Select the events sorted by: start_date / time / the_title

    My first guess was to make a custom query, but i am no mysql expert, so if you are, can you please give me some directions?

    My second try was to sort the WP_Query by the meta_value of the start_date key. But i can’t seem to use an array within my query. This doesn’t work.

    $loop = new WP_Query( array( 'post_type' => 'WPSM_event', 'posts_per_page' => -1 , 'order' => 'asc', 'orderby' => 'meta_value', 'meta_key' =>  '_datetime['start_date']' ) ); $count = 0;
    	while ( $loop->have_posts() ) : $loop->the_post(); $count ++;

    I really hope someone can help me out here. I look forward to finish this thing and if it’s good enough submit it to the wordpress plugin dir. So please let me know what you think!



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

    Well, it cant sort by 'meta_key' => '_datetime['start_date']'
    All these options used to build correct SQL query and it’s not supposed to sort by part of serialized value because this is slow and ineffective.

    Solution is simple, you should put each value to own meta and then you will be able to sort them.

    This is an interesting part of wp_query that is unfortunately not as versatile as I wish it was. That said, I have done a lot of sorting my meta key such as:

    'meta_key' => '_my_meta_key',
         	'orderby' => 'meta_value',
            'order' => 'ASC'

    I think the key would be not have the meta keys stored as an array, but each as a separate value. in your case like this:


    then you could use wpquery to sort by any of the keys like this:
    `’meta_key’ => ‘_my_key_start_date’,
    ‘orderby’ => ‘meta_value’`

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stage manager custom post types’ is closed to new replies.