0

I have the following code to display posts with a custom taxonomy but it's not working. It just displays all the posts:

// Add Shortcode
function custom_shortcode( $atts ) {
    $atts = shortcode_atts( array(
        'project' => ''
    ), $atts );
    $today = date("Y/m/j");
    $args = array(
      'post_type'   => 'evenement',
      'tax_query'         => array( array(
            'taxonomy'  => 'project',
            'field'     => 'slug'
        ) ),
      'order'       => 'ASC',
      'post_status' => 'publish',
      'meta_key'    => 'eventdate_begindate',
      'orderby'     => 'meta_value',
      'meta_query' => array(
        array(
           'key' => 'eventdate_begindate',
           'meta-value' => $value,
           'value' => $today,
           'compare' => '<=',
           'type' => 'CHAR'
       )
));

    $events = new WP_Query( $args );
    if( $events->have_posts()  ) :
        $html = '<div class="owl-carousel owl-lazy">';
          while( $events->have_posts() ) :
            $events->the_post();
            $loc = get_post_meta(get_the_ID(), 'eloc_location', true);
            $bdate = get_post_meta(get_the_ID(), 'eventdate_begindate', true);
            //print_r($bdate);
            $bdatef = DateTime::createFromFormat("Y-m-d", $bdate);
        $html .= '<div class="evsl-event" style="background-image:url(' . get_the_post_thumbnail_url($post->ID) . ')">';
        $html .= '<div class="evsl-event-content">';  
        $html .= '<h4>' . get_the_title() . '</h4>';
        $html .= '<span> ' . $bdatef->format('d F Y') . '</span><br>';
        $html .= '<span>' . $loc . '</span>';
        $html .= '</div>';
        $html .= '</div>';    
          endwhile;
          wp_reset_postdata();

        $html .= '</div>';

    else :
      esc_html_e( 'Er zijn geen evenementen', 'text-domain' );
    endif;

return $html;
}
add_shortcode( 'evenementen', 'custom_shortcode' );

The shortcode on the page is [evenementen project="skills-the-finals"]

  • What is $value? – Eduardo Escobar Aug 6 at 18:01
  • Also, your tax query says to refer to the project slug, but you never actually tell it which project to look for – Tom J Nowell Aug 6 at 18:37
  • In meta query you have key 'meta-value', but it should be 'value' – nmr Aug 6 at 19:08

Your Answer

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

Browse other questions tagged or ask your own question.