Thanks to Brad Dalton at wpsites.net for getting me to the answer.
-
Install Advanced Custom Fields plugin. Create a custom field called price, formatted as a number.
-
Use the code below (based on Bill Erickson’s tutorial):
add_action( 'pre_get_posts', 'kr_change_posts_order' );
function kr_change_posts_order( $query ) {
if ( $query->is_main_query() && !is_admin() && !is_page() ) {
$orderby = genesis_get_custom_field( 'price' );
$query->set( 'cat', ( array( 5, 6, 15 ) ) );
$query->set( 'meta_key', 'price' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'DESC' );
}
}
This sorts by price, descending, for three post categories with IDs 5, 6 and 15.
Related Posts:
- How to exclude latest x posts from a paginated query?
- WordPress Number of Posts Not Changing With posts_per_page
- Replace Main Query With Custom Query
- Custom Order in WP Query
- how to get posts ids inside pre_get_posts filter?
- How can I sort posts by the date and a custom meta field?
- is there a way to show the the post title after the image?
- How to exclude latest x posts from a paginated query?
- wp_query with ajax
- How do I display main query posts in random order using add_filter
- WP_Query sort by meta_value_num or date
- Creating Ordered Query using Meta_key
- Show posts between two Custom Fields date
- How to get Tags with specific post id
- how can i change WP main archives loop to sort by name or title
- How to automate featured posts number? [duplicate]
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- How to display all posts divided/ordered by post date? [closed]
- Why Query is returning empty array?
- How do I extract just the post ID of the first item in whatever WP_Query returns?
- Show post content and title in diferent divs using WP_Query using a loop
- Customize rel=canonical tag for single blog post
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- How to save meta checkbox WordPress
- Why are my paginated posts always returning the same results?
- Ignore latest two posts
- Is it possible to use WP_Query to only pull posts with attachments?
- Show posts by author of membership level (Paid Membership Pro)
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- How to calculate the average of a post meta value(Numeric) of a specific author
- Every second post different class in blog view
- Loop doesn’t exclude the specified category in home page
- Get posts with multiple categories
- Do not show children of a category
- Is there any way to tell when wp_postmeta has been updated?
- post__in not working with pre_get_posts, but post__not_in does work
- Display posts of specific category term
- Print out last 3 blogposts
- why the same code got different results when using query_posts in functions.php and index.php
- Query posts by Author and/or by Tag
- Query for first 3 posts to change the look and feel
- How to get posts published on the latest date?
- wpColorPicker – problem with implementation to post meta
- Why posts array is empty?
- Can’t understand why sometimes a [caption] field appears
- Page and post loop same template
- Getting blog pagination to work on page set as front page
- How to group only VISIBLE posts? [closed]
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- search blog posts by author first name and or last name
- Change post author without using wp_update_post()
- Show metabox value last post excerpt, title and link
- if in category but only with post meta
- On what hook can I get the queried object’s final state?
- unique post in “$args” of wp_query display more than one post
- Display current post position in Elementor Posts widget
- Why in my query is display two title?
- Migrate posts from category and sub-category via SQL
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- How to give classname to post if post has no content?
- Update post meta within save_post action
- Custom wp-query in wordpress rest api
- Display post number by category
- Updating post meta for checkbox
- Saving Post Data in Another Database
- WP_Query: Show 10 posts in date order, first three random
- How can I insert a new markup element after 4 posts automatically? [closed]
- Exclude some posts from displaying in wp_query based on some condition
- posts_per_page returning only one post
- Modify main query before it run without pre_get_post
- If no posts exist for current day and month, show the next available day of posts
- WordPress Loop: How to display recent posts in multiple divs
- Random posts that always include a particular post?
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- Related Posts function not working
- How to retrieve certain number of images from a wordpress post?
- WordPress post filter menu
- Custom Post Limit for homepage only without plugin?
- Custom permalink for each post
- How can I tell if a post has been published at least once?
- Is there a way getting post fields using `transition_post_status`
- Automatic blog page with custom design [closed]
- How to display post list in a table layout (multiple queries in single loop)
- Conflict array_splice on loop and query in widget
- Add multiple meta keys to a post at once
- Show number of posts by logged in user
- How does WP decide how to display a page
- Not all posts showing in query
- how to handle the loop using filling bootstrap grid structure?
- Get all custom posts with a certain taxonomy
- WP_Query custom field pass the post id
- How to convert query sql to shortcode in wordpress?
- Link to date_query results in WordPress