0

I need someone to answer this question. I have metabox which shows date:

 $date = rwmb_meta( 'pb_match_date', '', $post->ID );

I want to get all the associated posts with specific date of that metabox as follows:

23 Oct 16:

  1. Post 1
  2. Post 2

27 Oct 16:

  1. Post 1
  2. Post 2
  3. Post 3

What will be the query?

$args = array(
    'post_type' => array( 'post' )        
);

$my_query = null;
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post(); 
    $dates = rwmb_meta( 'pb_match_date','', $post->ID);
    foreach ( $dates as $date ) { 
        //Is it correct? If not then what is the way?
    }
endwhile;
wp_reset_postdata(); ?>
5
  • What does rwmb_meta do?
    – socki03
    Nov 23, 2016 at 21:53
  • As same as :get_post_meta()
    – bdtheme
    Nov 23, 2016 at 21:54
  • Are you only requesting a specific date? Or are you attempting to list all posts and then organize them based on that pb_match_date field?
    – socki03
    Nov 23, 2016 at 22:00
  • @socki03 No, rwmb_meta() is not the same. And in case you want to keep this open and on topic: Go with plain meta handling instead of Rilwis Metabox plugin.
    – kaiser
    Nov 23, 2016 at 22:25
  • @kaiser Thanks for the info, hadn't seen that function before and was too lazy to learn about a plugin I didn't recognize.
    – socki03
    Nov 23, 2016 at 22:42

1 Answer 1

0

If I've understood the case correctly your $args should be something like that:

$args          = array(
                'posts_per_page' => 5, // what ever you like
                'paged'          => $page, // page number tracker
                'post_type'      => 'post', // or change to custom
                'post_status'    => array( 'draft', 'publish' ),
                'meta_query'     => array(
                     array(
                         'meta-key'     => 'pb_match_date',
                         'meta-compare' => 'EXISTS'
                      ),
                 ),
            );

This will return all posts where 'pb_match_date' exists, then you can extract the value and build upon.

You can always reference the codex for more details:

https://codex.wordpress.org/Class_Reference/WP_Query

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.