admin管理员组文章数量:1417546
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"]
本文标签: Custom post type shortcode with taxonomy attribute not working and no errors
版权声明:本文标题:Custom post type shortcode with taxonomy attribute not working and no errors 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745264389a2650508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论