Hi, Noone responds but I try to use pre_get_posts:
function my_pre_get_posts( $expo_query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $expo_query ;
}
// only modify queries for 'exposiciones' post type
if( isset($expo_query ->query_vars['post_type']) && $expo_query ->query_vars['post_type'] == 'exposiciones' ) {
$expo_query ->set('meta_key', 'expo_start_date');
$expo_query ->set('orderby', 'meta_value');
$expo_query ->set('order', 'DESC');
}
// return
return $expo_query ;
}
add_action('pre_get_posts', 'my_pre_get_posts');
without success. đ
I try to resolve in another way, and the result now is “array”. Where is my mistake?
<div class="news-group">
<?php
if( have_rows('news_home_list') ): while ( have_rows('news_home_list') ) : the_row();
if( get_row_layout() == 'news_home_list_plus' ):
$news = get_sub_field('news_home_select');
$title = get_the_title($news->ID);
$values = get_field('news_abstract', $news->ID);
?>
<div class="news">
<strong><?php echo $title; ?></strong>
<?php
if( $news ): ?>
<p><?php echo ( $news->$abstract ); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
Hi, thanks for the response but or I don’t understand it, or my case is a lit bit diverse that I’d describe for you.
I try to use
$value = get_field('field_name', $news->ID);
directly in the flexible content template tag but it doesn’t work. See it:
<div class="news-group">
<?php
if( have_rows('news_home_list') ): while ( have_rows('news_home_list') ) : the_row();
if( get_row_layout() == 'news_home_list_plus' ):
$news = get_sub_field('news_home_select');
$title = get_the_title($news->ID);
$abstract = get_field('news_abstract', $news->ID);
?>
<div class="news">
<strong><?php $title; ?></strong>
<p><?php $abstract; ?></p>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
I try to use setup_postdata() doc example but nothing, đ
<div class=ânews-groupâ>
<?php
if( have_rows(ânews_home_listâ) ): while ( have_rows(ânews_home_listâ) ) : the_row();
if( get_row_layout() == ânews_home_list_plusâ ):
$news = get_sub_field(ânews_home_selectâ);
$featured_posts = get_field(ânews_home_selectâ);
if( $featured_posts ): ?>
<?php foreach( $featured_posts as $post ):
// Setup this post for WP functions (variable must be named $post).
setup_postdata($post); ?>
<div class=ânewsâ>
<div class=ânews-contentâ>
<a href=â<?php the_permalink(); ?>â><?php the_title(); ?></a>
<span>A custom field from this post: <?php the_field( ânews_abstractâ ); ?></span>
</div>
<?php endforeach; ?>
<?php
// Reset the global post object so that the rest of the page works correctly.
wp_reset_postdata(); ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
I remember that my post object is into flexible content…
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.