https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
<ul>
<?php
$item=0;
$attr = array(
'post_type' => 'lyrics',
'date_query' => array( array( 'after' => '1 month ago' ) ),
'post_status'=> 'publish',
'meta_key' => 'youtube_views',
'orderby' => 'meta_value',
'order' => 'DESC',
'posts_per_page' => 10
);
$loop = new WP_Query( $attr );
while ( $loop->have_posts() ) : $loop->the_post();
$song_name = get_the_title();
/*YOUTUBE QUERY HERE*/
// $Yviews = 1234;
?>
<li>
<?php echo esc_attr($song_name).' ('.$Yviews.' views)'; ?>
</li>
<?php endwhile; wp_reset_query(); ?>
</ul>
Related Posts:
- Count posts returned by get_posts in external PHP script
- How to use external API content in place of WP posts using $wp_query?
- Add parameter to first post only
- How to search by slug and old slug in single API
- wc_get_products() return empty object
- Wrote a WP Cron Plugin and it triggers a fatal error upon activation
- why ignore_sticky_posts in sticky post query
- get_query_var( ‘paged’ ) not working outside of homepage
- get custom post type by tag
- Does tax_query really beats meta_query in all situations?
- Using WP_Query To Get Posts Randomly From today
- How to know which one is the main query?
- WP_Query can’t exclude more than 1 author?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to order posts by custom WP role?
- posts2posts query using connected_items array issue [closed]
- WP Query and order by particular specified IDs
- Get the post permalink within the loop but without additional DB query
- Display revision if post status is pending
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- How To Remove/hide some specific categories from two different categories widget from sidebar
- WP Query search for attachments and their exact title
- How to add another parameters to WP_Query?
- Display link to taxonomy archive only if it has posts with certain custom field values
- Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?
- How to display posts month by month?
- Display posts with date wordpress default
- Query different number of posts with different formats in one go
- Extending woocommerce admin product search
- Pagination is broken and I need help fixing it
- Query total number of posts
- How to display a posts 1 year ago with custom WP_Query loop?
- Check on which page specific result exist
- WC displaying products from category
- Loop returning only 1 result
- Fetch posts that match term slug first two letters (wp query)
- pagination with numbers for WP_User_Query
- How does one perform a sub query with different post types
- Query with search and subscribers only output
- Stuck in the query loop
- Query Page Content From Theme Options?
- Filter wordpress post categories with jquery/ajax and pagination?
- Taxonomy order exception for specific term
- next_post_link / previous_post_link not working with WP_Query
- How to Create a Random List of Child Pages
- Is there a way to make this kind of loop shorter and nicer?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- WP Query ordering on a meta field for posts with a date in the future not ordering by datetime
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Pagination on template page for custom query redirecting to index.php
- Get all posts with empty meta_value
- Count identical post titles
- get_page meta query not working, maybe a bug?
- Exec wp query in slow motion to avoid memory error?
- Query by date from custom field
- Remove post type filter added by the plugin in the final query
- How to get more data of a post by wp_query
- What is wrong with my WP_Query Arguments?
- Query of all pages, including children, ordered by meta key
- specific post is not excluded from the loop
- Unable to paginate a custom page query
- How to change the default post type over the loop?
- How to WP Query custom multiple custom taxonomies?
- Sort posts using multiple custom fields and menu_order in single query?
- get_the_terms has strange result since version 6.0
- How to display posts from custom post type category(custom Taxonomy) wise?
- How to make WPQuery custom post type work in Twig / Timber
- get_posts return only first result
- How to allow a variable with “/” in wordpress url
- Bootstrap grid while loop
- How to get taxonomy image attached to a Post Type WordPress
- How to display a post(by id) along with css in a page?
- search multiple keywords with wp_query using one query
- Order posts by tags count?
- update_post_meta performance in a loop woocommerce
- Display posts side by side with custom query
- Is there a way to control both Order By and Order query parameters from one input field
- Pre get posts sort by meta key returns no results if meta key does not exist
- return child post if available otherwise parent post
- Custom Order Current Query: By Meta Key and Category
- Search has query that will return no results
- remove_action – pre_get_posts – does not restore original query
- why ignore_sticky_posts in sticky post query
- How to define a custom hierarchy for terms?
- WP_User_Query not searching numbers?
- Select Unique Posts for a List of Tags
- How to modify WP Query to target the first most recent post to adjust content
- Best way to Order Post in Home without a plugin
- Retrieving category pages from subcategory returns empty sets
- WP_query issue with no posts
- How to get query results for the next page
- Iterate through ID’s in loop
- Loop through multiple custom fields with increasing number
- Multiple loop for “featured” items returns wrong posts
- Get WP_Query query after execution?
- Query string form $_GET[‘value’] is not working as meta value in wp_query
- query_posts problem – need help
- 294 Queries on Mainpage of WordPress
- Pagination on custom post type not working
- How to efficiently find “duplicate” posts, where the titles are different, using metadata to match posts?