0

I am using the FT Calendar Plugin. My question is how can I order posts of a custom post type by the event calendar date?

So for instance I have a CPT named "Events" and for each event post a calendar date is added. Problem is that the page that lists the event posts doesn't order the posts by event calendar date, but the standard wordpress ordering. Is there a way to order them in my query instead by the FT Calendar event date?

The data for the event dates are stored in their own table "rfw_ftcalendar_events".

id | calendar_id | post_parent | start_datetime      | end_datetime

1  | 2           | 210         | 2013-04-05 15:00:00 | 2013-04-05 16:00:00
1

My guess is that the calendar date is some sort of meta field for the custom post type. I'd find that out and add that as a variable for my query.

You might be able to use something like this

<?php $loop = new WP_Query( array( 'post_type' => 'events', 'meta_key'=>'start_datetime',  'orderby' => 'meta_value', 'order' => ASC) ); while ( $loop->have_posts() ) : $loop->the_post(); ?>
  • 1
    But of course you wouldn't use query_posts, right? – vancoder Apr 30 '13 at 17:46
  • I just updated my question. The data is actually stored in a separate table "rfw_ftcalendar_events". – dragonfeet2012 Apr 30 '13 at 19:07
  • @vancoder wouldn't it though? When he's trying to display all posts of the custom post type, he'd have to query it, right? At which point he could add the query arguments and orderby=meta_value&meta_key=start_datetime ...then again, I could be wrong or misunderstanding what he's looking for? – NW Tech Apr 30 '13 at 19:28
  • @NWTech Your concept is fine, but query_posts is best avoided. See here for why. That said, the OP has now specified a custom table, so this is all academic. – vancoder Apr 30 '13 at 20:23
  • @vancoder thanks for enlightening me on my deprecated example. – NW Tech Apr 30 '13 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.