Last active
October 14, 2021 19:35
-
-
Save aldolat/432f622f2ff576e2e570cf651137d717 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'post', | |
//'category_name' => 'markup', | |
'meta_query' => array( | |
array( | |
'key' => 'rating', | |
'value' => array( 2.42, 2.47 ), | |
'compare' => 'BETWEEN', | |
//'type' => 'NUMERIC', | |
//'type' => 'DECIMAL', | |
), | |
), | |
'posts_per_page' => -1, | |
'orderby' => 'meta_value_num', | |
'order' => 'DESC', | |
'post_status' => 'publish', | |
'ignore_sticky_posts' => true, | |
); | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) { | |
echo '<ul>'; | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
$the_custom_field = get_post_meta( $query->post->ID, 'rating', false ); | |
?> | |
<li style="margin-bottom: 1em;"> | |
Post title: <a href="<?php echo esc_html( get_permalink( $query->post->ID ) ); ?>"><?php echo esc_html( get_the_title( $query->post->ID ) ); ?></a><br /> | |
Category: <?php echo get_the_term_list( $query->post->ID, 'category', '', ', ', '' ); ?><br /> | |
Rating: <?php echo esc_html( $the_custom_field[0] ); ?> | |
</li> | |
<?php | |
} | |
echo '</ul>'; | |
} else { | |
echo '<p>No posts yet.</p>'; | |
} | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment