admin管理员组文章数量:1278721
In the tax_query, I have used the 'term' = array( $category->slug ). I'm getting an error notice where using $category->slug, however, in the frontend it displays the slug of the term.
Please help me to debug it.
// Shortcode [phd_vacancies]
<?php
add_shortcode( 'phd_vacancies', function() {
ob_start();
global $post; // data from the current post in the WP loop
$categories = get_the_terms( get_the_ID(), 'country' );
foreach( (array) $categories as $category ) {
$args=array(
'post_type' => 'job',
'post_status' => 'publish',
'posts_per_page' => 10,
'orderby' => array('title' => 'DESC'),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'country',
'field' => 'slug',
'terms' => array( $category->slug ), // PHP Warning: Attempt to read property "slug" on bool
),
array(
'taxonomy' => 'position',
'field' => 'slug',
'terms' => array( 'phd' ),
),
array(
'taxonomy' => 'current-status',
'field' => 'slug',
'terms' => array( 'ongoing' ),
),
),
//'no_found_rows' => true,
'cache_results' => false,
);
}
$query_phd_vacancies = new WP_query( $args );
echo '<h3>'. esc_html( $query_phd_vacancies->found_posts ) . 'PhD Positions available in' . esc_html( $category->slug ) . '</h3>(now viewing first' . esc_html( $query_phd_vacancies->post_count ) . 'only)<br>'; // PHP Warning: Attempt to read property "slug" on bool
if( $query_phd_vacancies->have_posts() ) {
while( $query_phd_vacancies->have_posts() ) {
$query_phd_vacancies->the_post();
?>
<li><a href="<?php the_permalink()?>" target="_blank" rel="noopener noreferrer">
<?php the_title(); ?>
</a></li>
<?php
}
}else echo 'Sorry No PhD Positions found';
wp_reset_postdata();
return ob_get_clean();
}
);
本文标签: termsPHP Warning Attempt to read property quotslugquot on bool in tax query
版权声明:本文标题:terms - PHP Warning: Attempt to read property "slug" on bool in tax query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741245484a2364792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论