Order taxonomy terms in ASC order while generating dynamic post title using CRED

To get hierarchical taxonomy terms sort in a ASC order you need to add “orderby” clause with WP function: wp_get_post_terms(). you can use term_id with orderby clause. Could you please try following code:


add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==XXXX) {
$term_list = wp_get_post_terms($post_id, 'listing-type', array("fields" => "names","orderby"=>"term_id"));
$auctiontype = join("-",$term_list);
$auctiondate = get_post_meta($post_id, 'wpcf-auction-ending', true);
$auctiondate = date('d-m-Y',$auctiondate);

$term_list= wp_get_post_terms($post_id, 'car-brand', array("fields" => "names","orderby"=>"term_id"));
$carbrand = join("-",$term_list);

$title= $auctiontype. ': le ' . $auctiondate. ' - ' . $carbrand;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}

Ticket URL: https://wp-types.com/forums/topic/get-custom-taxonomy-in-auto-title/#post-519488

Exclude children terms only from a specific post type from parent taxonomy archive

Please find below code which I tested with custom taxonomy called “hobby” which is assigned to default post type “post” and custom post type “student”. You should change the relative field with below code.


add_action( 'pre_get_posts', 'cyb_pre_get_posts' );
function cyb_pre_get_posts( $query ) {

if( $query->is_tax( 'hobby' ) && $query->is_main_query() && !is_admin() ) {

$children = get_term_by( 'slug', $query->query_vars['hobby'], 'hobby' );
if( $children->parent == 0 ) {

/// find child post entries
$posts_array = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'student',
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'hobby',
'field' => 'slug',
'terms' => $query->query_vars['hobby'],
'include_children' => false
))));

$posts_post = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post',
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'hobby',
'field' => 'slug',
'terms' => $query->query_vars['hobby'],
'include_children' => true
))));

$query->query_vars['post__in'] = array_merge($posts_array,$posts_post);
}

}
}