$conven = get_field('conveniences');
echo $conven['value'] .' '. $conven['label'];
Использовал ACF например для блока с преимуществами, но данные поля доступны только в рамках данной страницы, а иногда требуется выводить в нескольких местах
the_field('field_name', page_id)
<?php $attached_images = get_attached_media( 'image' ); ?>
<div><?php echo count($attached_images); ?> прикрепленных изображений</div>
function count_img_in_post ($content) {
preg_match_all('/<img(.*?)src=("|\'|)(.*?)("|\'| )(.*?)>/s', $content, $images);
if(has_post_thumbnail()) {
return count($images[0]) + 1;
}
return count($images[0]);
}
<?php $content = get_the_content(); ?>
<div><?php echo count_img_in_post($content); ?> прикрепленных изображений</div>
$terms = get_terms( array(
'taxonomy' => 'pa_proizvoditel'
) );
foreach( $terms as $term ) {
$terms_ids[] = $term -> term_id;
}
$args = array(
'posts_per_page' => -1,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'pa_proizvoditel',
'field' => 'term_id',
'terms' => $terms_ids,
),
),
);
$custom_query = new WP_Query( $args );
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) :
$custom_query->the_post();
the_title();
echo get_field("name", $terms);
endwhile;
endif;
wp_reset_postdata();
$args = array(
'date_query' => array(
array(
'after' => 'January 1st, 2019',
'before' => 'January 31st, 2021',
'inclusive' => true,
),
),
);
$query = new WP_Query( $args );
$args = array(
'status' => 'approve',
);
$comments = get_comments( $args );
foreach ( $comments as $comment ) :
echo $comment->comment_author . '<br />' . $comment->comment_content;
endforeach;