0

I need display all custom posts (event), order them by custom field (date) and group by month: September

  • Event 1
  • Event 2

August

  • Event 3

July

  • Event 4
  • Event 5

I know, it is frequently asked question here, but despite the reading many similar issues, I can't do anything meaningful according them. So all posts are still ordered by default - by date of publishing. I will grateful for any hints. This is my code:

<?php
$args = array(
'post_type'=>'event',
'posts_per_page'=> -1,
'order'=> 'DESC',
'orderby'=> 'meta_value',    
'meta_key'=>'event_start_date'
)

$events = new WP_Query( $args ); 
if ($events->have_posts()) : while (have_posts()) : the_post();

the_title();
// (etc.)

endwhile;
endif; 
?>
1
  • What is your date format in your custom field Commented Sep 18, 2015 at 12:34

1 Answer 1

1
<?php

  $period = date("Y-m-d");

  $args = array(
  'post_type'=>'event',
  'posts_per_page'=> -1,
  'order'=> 'DESC',
  'orderby'=> 'meta_value',    
  'meta_key'=>'event_start_date'
  'meta_value' => $period,


 )

 $events = new WP_Query( $args ); 
if ($events->have_posts()) : while (have_posts()) : the_post();

the_title();
// (etc.)

endwhile;
endif; 

?>   

Please follow below link for details.

Link for details

link for code source

Thanks!

3
  • Hm, something is wrong: "Oops, Post Not Found!" Commented Sep 18, 2015 at 12:18
  • please check second link where code example is given.
    – jas
    Commented Sep 18, 2015 at 13:29
  • Sorry, I overlooked the links. Thank you. I am going to study :-) Commented Sep 18, 2015 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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