[Support request] Add secondary sort parameter

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Add secondary sort parameter

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by  Tom 2 weeks, 2 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6505

    Adam
    Participant

    I’ve added a function to the plugin which allows it to display values defined in a custom meta box in post editing.

                  <?php if( get_field('active') ): ?>
                     <h2 class="active"><?php the_field('active'); ?></h2>
                  <?php endif; ?>

    I want to use ‘active’ as a secondary ‘orderby’, so that the posts maintain their default ordering (chronological) AND give priority to posts which are ‘active’. So an active post from 1-2-18 will be displayed above a non-active trade from 1-1-18.

    Any help would be greatly appreciated.

    Thanks

    #6516

    Adam
    Participant

    If anyone has a clue which files I need to edit to make this happen, that would help as well.

    I’m seeing the parameters for orderby in /wp-show-posts.php although they look incomplete. Not an expert in PHP but I could probably figure this out if I had some clues for where to look.

    Thanks

    Edit: If it’s easier, I’ll mention that I don’t need to edit the metabox for any of this. I just want all posts to also check for the custom field the_field('active') and use that as a sort parameter following the default parameter. If ‘active’ is found for a post, it should appear before any post without ‘active’.

    • This reply was modified 2 weeks, 4 days ago by  Adam.
    #6518

    Tom
    Keymaster

    Hey Adam,

    I’m not 100% sure how you’d do this, unfortunately.

    If you’re able to get help with the WP_Query parameters, we can integrate them into WP Show Posts, as it sets up a WP_Query instance.

    It may be worth asking over on wordpress.stackexchange.com if it’s possible to bring those posts with a meta value to the top using WP_Query. If someone can point us in the right direction there, we can make it work in the plugin.

    Here’s something I found, but I’m not sure it’s exactly what you’re looking for: https://wordpress.stackexchange.com/questions/278337/wp-query-order-by-multiple-meta-keys-fields

    #6535

    Adam
    Participant

    Thanks for your reply Tom. I’m doing some digging now, I’ll update here if I make any progress on that.

    Best,
    Adam

    #6546

    Tom
    Keymaster

    Sounds good 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.