add_filter( 'wp_insert_post_data', 'toster256163_comments_on' );
function toster256163_comments_on( $post_data ) {
if ( $post_data['post_type'] === 'movies' ) {
$post_data['comment_status'] = 'open';
}
return $post_data;
}
$cur_terms = get_the_terms( $post->ID, 'genres' );
if( $cur_terms && ! is_wp_error( $cur_terms ) ) {
$array = array();
foreach( $cur_terms as $cur_term ) {
$array[] = $cur_term->name;
}
$comma_separated = implode( ", ", $array );
echo '<div>Жанры: ' . esc_attr( $comma_separated ) . '</div>'; // term1, term2, term3
}
if(!empty($array)){
$comma_separated = implode(", ", $array);
echo '<div>Жанры:' . ' ' . $comma_separated . '</div>'; // term1, term2, term3
}
<?php
$array = array();
$cur_terms = get_the_terms( $post->ID, 'genres');
foreach( $cur_terms as $cur_term ){
$array[] = $cur_term->name;
}
$comma_separated = implode(", ", $array);
echo $comma_separated; // term1, term2, term3
?>
<?php
$posts = get_field('relationship-field');
if( $posts ):
$new_posts = array(); ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post);
$new_posts[] = '<a href="'.get_the_permalink().'">'.get_the_title().'</a>'; // сложили все в массив
?>
<?php endforeach;
$done_post = implode(",", $new_posts);
echo $done_post; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>