• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

KarenR

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password
  • Profile
  • Topics Started
  • Replies Created
  • Engagements
  • Favorites

Forum Replies Created

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • March 1, 2020 at 10:52 am in reply to: Sort selected post categories descending by custom field, "price" #497051
    KarenR
    Participant

    Thanks to Brad Dalton for the solution. Adding it here in case it will help someone else in the future.

    This sorts posts by the custom field "price" in descending order, targeting only three categories with IDs of 5, 6 and 15.

    1. Install Advanced Custom Fields plugin by Eliot Condon. In the plugin setup, create a field called price, formatted as a number.

    2. Use the following code in functions.php:
    (This came from Bill Erickson, with some slight modification.)

    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' );
    }
    }

    Thank you,
    Karen

    March 1, 2020 at 9:46 am in reply to: Sort selected post categories descending by custom field, "price" #497050
    KarenR
    Participant

    Hi Brad,

    I don't have the Toolset plugin, I was just looking for code snippets online. I always search using "Genesis" and/or "Studiopress" but I wasn't having any luck. I also don't have ACF; I've just written into the functions.php file. I am not really a PHP programmer; I use and modify code snippets that you and others offer. (Which is greatly appreciated!)

    Originally it seemed that their code was helping but I just tested by taking it out and I see that it does nothing. Which leaves me with

    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' );
    $query->set( 'order', 'DESC' );
    }
    }

    February 29, 2020 at 8:40 pm in reply to: Sort selected post categories descending by custom field, "price" #497045
    KarenR
    Participant
    This reply has been marked as private.
    February 29, 2020 at 8:20 pm in reply to: Sort selected post categories descending by custom field, "price" #497044
    KarenR
    Participant

    Hi Brad, I found the code on a public-facing Toolset post. If global $WP_Views is not part of standard WP, then clearly that is part of the problem. But it did make a difference when I tried changing UNSIGNED to NUMERIC (while I was trying different things), so I thought it was part of core.

    Karen

    February 29, 2020 at 1:46 pm in reply to: Sort selected post categories descending by custom field, "price" #497042
    KarenR
    Participant

    Hi, can anyone help with this, please?

    Karen

    February 24, 2020 at 1:17 pm in reply to: Sort selected post categories descending by custom field, "price" #496930
    KarenR
    Participant

    I put the code in the functions.php file of the theme.

    Karen

    February 24, 2020 at 12:57 pm in reply to: Sort selected post categories descending by custom field, "price" #496928
    KarenR
    Participant

    Hi Anita,

    This from a Toolset post:
    function func_orderby_asking_price( $orderby ) {
    global $WP_Views;

    if($WP_Views) {
    $orderby = str_replace( 'price', "cast(replace(trim( leading '$' from price),',','') AS UNSIGNED)", $orderby );
    }

    return $orderby;
    }
    // end
    This from Bill Erickson (shout out to Bill, thank you!) with some modifications:
    add_filter('posts_orderby', 'func_orderby_asking_price' );

    add_action( 'pre_get_posts', 'kr_change_posts_order' );
    function kr_change_posts_order( $query ) {
    if ( $query->is_main_query() && !is_admin() ) {
    $query->set( 'cat', ( array( 5, 6, 15 ) ) );
    $query->set( 'orderby','meta_value' );
    $query->set( 'meta_key','price' );
    $query->set( 'order', 'DESC' );
    }
    }
    //end
    I can't help but think that it is something simple that I am overlooking; the code seems to work EXCEPT for the fact that it sorts by the first digit, not by all digits.

    Karen

    February 24, 2020 at 12:11 pm in reply to: Sort selected post categories descending by custom field, "price" #496926
    KarenR
    Participant

    Hi Anita,

    I'm using Education Pro.

    Karen

    July 10, 2017 at 5:54 pm in reply to: Trying to make featured posts horizontal with Education Pro #208937
    KarenR
    Participant

    Ha! I knew it was just one thing I wasn't seeing. Thank you so very much; I can get the rest from here.

    All the best in your endeavors.

    Karen

    July 10, 2017 at 4:15 pm in reply to: Trying to make featured posts horizontal with Education Pro #208929
    KarenR
    Participant

    Sorry, typo, I meant "but they will only line up vertically"

    Karen

  • Author
    Posts
Viewing 10 posts - 1 through 10 (of 10 total)

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble