Thursday, November 17, 2022
HomeWordPress Developmentphp - Is there a approach of displaying associated posts from lowest...

php – Is there a approach of displaying associated posts from lowest hyrachical order (lowest youngster class to dad or mum class)


Right here is my code, at the moment when viewing a submit it ends displaying posts from second youngster class(second in hyracichal whereas we now have 4 phases). I would like it to show posts from 4th youngster class, if no posts let it fall again to third youngster class, to 2nd youngster and dad or mum class. How am i able to archive that? its a wordpress web site

<?php
international $carspot_theme;
$pid = get_the_ID();
if ($carspot_theme['Related_ads_on']) {
    $classes = array();
    if ($carspot_theme['related_parent_or_child'] == true) {
        $post_categories = wp_get_object_terms($pid, array('ad_cats'), array('orderby' => 'term_group'));
        if (is_array($post_categories) && $post_categories != '') {
            foreach ($post_categories as $c) {
                $cat_terms = get_term($c);
                if ($cat_terms->dad or mum != 0) {
                    $classes[] = $cat_terms->term_id;
                }
            }
        }
    } else {
        $cats = wp_get_post_terms($pid, 'ad_cats', array('dad or mum' => 0, 'fields' => 'all')); // wp_get_post_terms($pid, 'ad_cats');
        foreach ($cats as $cat) {
            $classes[] = $cat->term_id;
        }
    }

    $args = array(
        'post_type' => 'ad_post',
        'posts_per_page' => $carspot_theme['max_ads'],
        'order' => 'DESC',
        'post__not_in' => array($pid),
        'tax_query' => array(
            array(
                'taxonomy' => 'ad_cats',
                'discipline' => 'id',
                'phrases' => $classes,
                'operator' => 'IN'
    )));
    $advertisements = new advertisements();
    if ($carspot_theme['related_ad_style'] == '1') {
        echo ( $ads->carspot_get_ads_grid_slider($args, $carspot_theme['sb_related_ads_title']) );
    } else {
        echo ( $ads->carspot_get_ads_list_style($args, $carspot_theme['sb_related_ads_title']) );
    }
}
?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments