Support

Account

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;
    }
    ?>