Home › Forums › General Issues › sort posts by custom fields – bad data returned if function created › Reply To: sort posts by custom fields – bad data returned if function created
function list_genre_posts($genre){
/* ADD THIS */
global $post;
//while ( have_posts() ) :
//the_post();
$posts = get_posts(array(
'posts_per_page' => -1,
'order' => 'ASC',
'post_type' => 'post',
'meta_key' => 'sumaryczna_ocena',
'orderby' => 'meta_value',
));
if( $posts ): ?>
<?php echo "<br><br>$genre<br>" ?>
<?php foreach( $posts as $post ):
setup_postdata( $post )
?>
<?php
$current_post_genre = get_field( "gatunek" );
/* if ( $current_post_genre == 'Thriller' ): ?>
<a href="<?php the_permalink(); ?>"><?php the_field('gatunek'); ?>: <?php the_field('nazwa_pl'); ?> - <?php the_field('rok_premiery'); ?></a><br>
<?php endif; ?> */?>
<a href="<?php the_permalink(); ?>"><?php the_field('sumaryczna_ocena'); ?> - <?php the_field('nazwa_pl'); ?> / <?php the_field('nazwa_oryginalu'); ?></a><br>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?><?php
//endwhile;
}
?>
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.