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 check if post meta key exists or not in wordpress database
- How to Change Order of Posts in Admin?
- The next_posts_link() works only with original $wp_query
- Query *only* sticky posts
- Accessing the post content with WP_Query
- Update all posts automatically when using post_meta
- Setting post meta data to random value during post status transition / on publish
- Get only modified posts
- How to output comments number of a post per day?
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- Does WP get all post_meta on POST page?
- If specific user role then sticky post
- Display posts with comments closed, with pagination?
- What Is meta_id In wp_postmeta?
- I want to query posts in monthly basis
- Custom WP_QUERY $args
- Improving WP_Query for performance when random posts are ordered
- Why won’t my taxonomy query show up?
- Limiting the number of posts in WP_Query leads to unexpected result
- pre_get_posts query between 2 dates (date stored in custom post meta)
- WP_Query with ajax handler returns the same posts
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How to do set post permalinks using 6 digit random unique function?
- Getting value from get_post_custom
- how to change the number of posts returned in a specific loop without making it global?
- posts_per_page option limits the number of Gallery items
- Nested WP_Query breaking loop
- Why Query is returning empty array?
- How to save meta checkbox WordPress
- meta_value timestamp older than now
- Get posts with multiple categories
- Do not show children of a category
- post__in not working with pre_get_posts, but post__not_in does work
- search blog posts by author first name and or last name
- if in category but only with post meta
- Display current post position in Elementor Posts widget
- 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
- Saving Post Data in Another Database
- posts_per_page returning only one post
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- How to retrieve certain number of images from a wordpress post?
- WordPress post filter menu
- Custom permalink for each post
- How can I tell if a post has been published at least once?
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- WP_Query custom field pass the post id
- Retrieve data from post meta meta_key having ‘_product_fq_image’ while having author_id and post type is PRODUCT
- WordPress query portfolio posts
- Current and next month posts
- Adding a meta box to determine the sidebar [closed]
- Get latest author posts inside the loop
- Same post appears in related Posts?
- Get post category as a separate string and url
- How to show multiple posts thumbnail, title and date in widget
- WP_Query outputs wrong post in custom post type
- Post meta not working
- how to show comments only author which send own posts in wordpress
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- How to sort WP_Post Object array by object field in php?
- What is proper filter or hook action to add data to the $post object?
- Order by meta_key field in WordPress not meta_value field value
- How to create page with post content in it?
- How to remove a post from results by ID after query?
- Show 5 posts and than 3 posts offset with pagination
- How to hide meta from search result only on pages?
- Override wp_link_pages pagebreak with filter
- WP_Query extended with AJAX
- post_name is not stored until post is published… where should I store my slug until it goes live then?
- Blog only showing one post even though more published
- WordPress loop uses unmodified posts array, why?
- Sort / Filter Queries
- Ordering posts alphabetically by meta keys and title
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- Order posts by separate menu order for different sub-categories
- Adding a category at even positions on main loop with modified pagination
- Why I getting only 1 post?
- What is wrong with this wp_query?
- Exclude sub sub categories from displaying in the archive page
- First post in loop displays twice
- If meta_key exists then don’t select this post?
- Translation related post text to Arabic
- date_query returning only the most recent post instead of the post published before today