<?php
// получаем id пользователя
$cur_user_id = get_current_user_id();
// Define custom query parameters
$custom_query_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'author' => $cur_user_id // выводим посты только этого пользователя
);
// Instantiate custom query
$custom_query = new WP_Query( $custom_query_args );
// Output custom query loop
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) :
$custom_query->the_post(); ?>
<?php the_title(); ?>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
echo get_the_title( $id );
echo get_field( 'field_name', $id );
<?php if ( $query->found_posts < 3 ) : ?>
<?php else : ?>
<?php endif; ?>
$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>