Ask the community

This is a community support forum where you can ask
questions and interact with other PremiumPress Customers.

Sort Coupons by Listing Type


  • ppt_retaildiscountcodes20-03-19_92369175
    Newbie 2 points
    April 14, 2019 at 4:26 pm

    I would like to order coupons by listing type.
    So for example if there is an actual coupon code i would like it to show up first in the store pages. So listing_type 1 above Listing_type 3 at all times.

    Can someone help me with that?

    Your help is much appreciated!

    King regards.

  • Marie
    Marie
    Super Guru 1,747 points
    April 30, 2019 at 2:03 am

    hi,

    you will have to create your own custom query and add in your own function for this.


  • ppt_retaildiscountcodes20-03-19_92369175
    Newbie 2 points
    May 17, 2019 at 5:43 pm

    Can you please tell me where should i add my custom query? and what query should i apply!

  • JamesD
    JamesD
    Super Guru 1,345 points
    May 17, 2019 at 8:10 pm

    Hello ppt_retaildiscountcodes20-03-19_92369175,
    Not really sure what you mean by “listing_type 1 3…etc”, however, info on this page should help with getting a query going:

    Sort by featured


  • ppt_retaildiscountcodes20-03-19_92369175
    Newbie 2 points
    May 18, 2019 at 10:47 am

    Okay! I have inserted the query in _functions.php file, but there’s another issue.
    After applying query, the sorting works but why my all the header and styling is disturbed?

    function _custom_order($wp_obj){

    if (!is_admin() && !$wp_obj->is_main_query() && !is_front_page())
    {
    echo ‘log’;
    $wp_obj->set(‘meta_key’, ‘type’);
    $wp_obj->set(‘orderby’, ‘meta_value’);
    $wp_obj->set(‘order’, ‘ASC’);

    }

    }
    add_action( ‘pre_get_posts’, array( $this, ‘_custom_order’ ) );

  • JamesD
    JamesD
    Super Guru 1,345 points
    May 18, 2019 at 9:58 pm

    @ppt_retaildiscountcodes20-03-19_92369175

    After applying query, the sorting works but why my all the header and styling is disturbed?

    Could be a couple things, like the special characters used to enclose data.

    See if this takes care of the header:
    Change ALL of the special characters and to a regular apostrophe '. They are differently encoded types of characters.
    Note: For future reference, if you see an error message it’s helpful to include that in your posts.

    The way this forum posts data could change them to the special characters, so I’m hoping this displays your code with the proper apostrophes:

    function _custom_order($wp_obj){
    if (!is_admin() && !$wp_obj->is_main_query() && !is_front_page())
    {
    echo 'log';
    $wp_obj->set('meta_key', 'type');
    $wp_obj->set('orderby', 'meta_value');
    $wp_obj->set('order', 'ASC');
    }
    }
    add_action( 'pre_get_posts', array( $this, '_custom_order' ) );
Viewing 6 posts - 1 through 6 (of 6 total)