terms – PHP Warning: Attempt to read property “slug” on bool in tax query

Question

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]

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__not_in' => array($post->ID),
    '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>{$query_phd_vacancies->found_posts} PhD Positions available in {$category->slug}</h3>(now viewing first {$query_phd_vacancies->post_count} only)<be>"; // 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();
} );

0
praba 1 month 2021-10-28T16:55:00-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse