0

I'm working on a custom shortcode function inside functions.php that would display a 'speakers' post-type, with 'featured speaker' ACF-checkbox and in a specific order set by ACF select-element. Bt the custom shortcode does not display anything. I've checked the code many times but I can't spot what I'm doing incorrectly.

add_shortcode( 'featured_speakers_clzd', 'custom_speakers_clzd' );function custom_speakers_clzd() {

$args = array(
    'post_type' => 'speaker',
    'posts_per_page' => -1,
    'post_status' => 'publish',
      'meta_query' => array(
                'relation' => 'AND',
                array(
                    'key'       => 'featured_speaker',
                    'value'     => '1',
                    'compare'   => '=',
                ),
                array(
                    'key' => 'speaker_order',
                    'orderby' => 'meta_value',
                    'order' => DESC,
                ),

            ),
    );

$query = new WP_Query( $args );

$out = '';

$out .= '<div class="full_section_inner">';

if ( $query->have_posts() ) {
    // The Loop
    while ( $query->have_posts() ) {
          $query->the_post();
          $out .= '<div class="vc_col-sm-3">';
                $out .= '<div class="wpb_single_image">';
                     $out .= '<a href="'.get_field('speaker_link').'" target="_blank">';
                          $out .= '<div class="vc_single_image-wrapper vc_box_border_circle  vc_box_border_grey">';
                                //$out .= '<img width="150" height="150" src="http://growcommerce.co/wp-content/uploads/2016/06/0c02f46-150x150.jpg" class="vc_single_image-img attachment-thumbnail" alt="Miki Beradelli, CEO, Kidbox" srcset="http://growcommerce.co/wp-content/uploads/2016/06/0c02f46-150x150.jpg 150w, http://growcommerce.co/wp-content/uploads/2016/06/0c02f46.jpg 296w" sizes="(max-width: 150px) 100vw, 150px">';
                          $out .= get_the_post_thumbnail( get_the_ID(), 'thumbnail' );
                          $out .= '</div>';
                     $out .= '</a>';
                $out .= '</div>';
                $out .= '<div class="separator transparent"></div>';
                $out .= '<div class="wpb_text_column wpb_content_element ">';
                     $out .= '<div class="wpb_wrapper">';
                          $out .= '<p style="text-align: center;">';
                                $out .= '<a href="https://www.linkedin.com/in/miki-racine-berardelli-b0022b3/" target="_blank">';
                                     $out .= '<span style="color: #ffffff;">'.get_the_title().'</span>';
                                $out .= '</a>';
                          $out .= '</p>';
                          $out .= '<p style="text-align: center;">';
                                $out .= '<a href="'.get_field('speaker_link').'" target="_blank">';
                                     $out .= '<span style="color: #ffffff;">'.get_field('company').'</span>';
                                $out .= '</a>';
                          $out .= '</p>';
                     $out .= '</div>';
                $out .= '</div>';
                $out .= '<div class="separator transparent"></div>';
          $out .= '</div>';
    }

    wp_reset_postdata();
}

$out .= '</div>';

return $out;

}

  • not sure what type of fields you set for featured_speaker or speaker_order, but why are you checking if they are in an array? did you put them in one? You can test where the problem is further by putting else statements to with your "ifs". This will let you know which testing is wrong. – rudtek Apr 21 '17 at 17:06
  • I was under the impression that I had to check if these vales were in the meta_query array – Anth Apr 21 '17 at 18:07
  • you already did that with the query. it won't show any posts that are in the meta query. – rudtek Apr 21 '17 at 18:33
  • I changed the function up as follows - still does not seem to work. – Anth Apr 21 '17 at 18:44
1

try this:

$args = array(
    'post_type' => 'speaker',
    'posts_per_page' => -1,
    'post_status' => 'publish',
      'meta_query' => array(
                array(
                    'key'       => 'featured_speaker',
                    'value'     => '1',
                    'compare'   => '=',
                ),
        ),
     'orderby' => 'meta_value',
     'meta_key' => 'speaker_order',
     'order' => DESC,   
    );

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.