1

Hi there my first time here! Im using CMB2 to attach posts to an post and i want to make a custom query with the values that cmb2 give me. I try this piece of code, but nothing appears. Can someone help me? I tried with a foreach loop and works, but on the debug bar i get a warning saying that im trying to get a property of a non object.

if ( ! function_exists( 'amob_rec_posts' ) ) {
      function amob_rec_posts() {
        global $post;
        $rec_posts = get_post_meta( get_the_ID(), '_amobrec_cmb2_post_search_ajax_demo_multiple', true );
        $args = array(
          'post__in' => $rec_posts,
          'ignore_sticky_posts' => 'true'
        );
        $the_query = new WP_Query( $args );
        // The Loop
        if ( $the_query->have_posts() ) :
        while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <div class="col-xs-12 col-sm-6 col-md-4">
          <article class="card">
            <header class="card-header">
              <?php if ( has_post_thumbnail() ) { ?>
                <a href="<?php the_permalink(); ?>">
                  <figure class="card-thumbnail">
                    <?php the_post_thumbnail(); ?>
                    <span class="icon-rounded"><i class="fa fa-link" aria-hidden="true"></i></span>
                  </figure>
                </a>
              <?php } ?>
            </header><!-- card header ends -->
            <section class="card-content">
              <a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
              <hr>
              <?php the_excerpt(); ?>
            </section><!-- card content ends -->
          </article><!-- article ends -->
        </div><!-- card wrapper ends -->
        <?php endwhile;
        endif;
        // Reset Post Data
      wp_reset_postdata();
      }
    }

0

Your Answer

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

Browse other questions tagged or ask your own question.