Support » Plugin: WPAdverts - Classifieds Plugin » Include Zero Price Results on sorting list

  • Resolved johndoe01

    (@johndoe01)


    Greetings and happy holidays.
    I have a doubt that i just noticed and i’m not sure where to enable it or maybe i just overlooked a setting.

    When I sort the category view to Cheapest appear the list from the cheapest to the expensive but the ads which have no price (marked in the site as POA) does not appear.

    How can I enable such option?

    Thanks in advance

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    hmm i am not sure i will check it once I am back in the office.

    After a new year please post a comment in this thread to remind me about it.

    Thread Starter johndoe01

    (@johndoe01)

    Hello. As requested here is a reminder about how can I include the results that have No price / Price Zero when i sort the list from lowest to highest price.
    Thanks in advance

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    thanks for the reminder 🙂 i will take a look at it today and post an update in this thread.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    currently in WPAdverts when a price is not entered in the Ad the meta_value for adverts_price is not saved at all, without going into too many details, this is causing problems because when sorting by meta field WP_Query is looking only at posts that have a value set.

    The easiest solution to this problem is to go to wp-admin / Classifieds / Options / Custom Fields panel edit the Price field and either:

    – make it required (but then each Ad will need to have a price greater than 0)

    – in the “Filters” section check “Number – converts a string to a number” then when the field will have no value entered the empty value will be converted and saved in the database as “0”, this should make no difference in the frontend except the Ad will be shown when sorting by price.

    One maybe unwanted effect will be that when showing cheapest first the ads without price will be the first to show since their price is set to 0.

    Ok, so this will take care of ads added/edited after enabling the filter, you will probably want to bulk set the price to 0 for all ads that do not have price right now?

    To do that you can run the following MySQL query from phpMyAdmin (i tested and it works fine but backup your database just in case something will go wrong)

    
    INSERT INTO wp_postmeta(post_id, meta_key, meta_value)
    SELECT ID, 'adverts_price', '0' FROM wp_posts WHERE post_type = 'advert' AND (SELECT meta_id FROM wp_postmeta WHERE post_id = ID AND meta_key = 'adverts_price') IS NULL
    
    Thread Starter johndoe01

    (@johndoe01)

    Hello, and thanks for reply.

    It worked as it follows:

    • Mandatory price with warning in the placeholder text
    • SQL Query

    Now the Zero Price Ads appears in the list of ads when sorted by price.
    Sometimes oneself overlook the obvious solutions but the SQL query works like a charm, since i had a hard time with a couple of ads that were rebelling by not showing despite the price was set to “0”.

    If something happens I’ll let you know.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.