• Resolved sellyk

    (@sellyk)


    Hi,
    There are some changes i want to make to the ads, however since there are so many it would be so tedious to do so.

    I figured the fastest way to do so would bulk changing via SQL.

    I figured out how to change the value but not the text. So whats happening is that even though the changes reflect on the front end, they aren’t changing on admin side. E.g. Take an ad for a pair of heels. Before, the heels were tagged as ‘Heels’ but i want to change all ads that have been tagged ‘Heels’ to be changed to ‘Stilettos’

    Then Via SQL i ran the following script

    UPDATE wp_xxxxxx_postmeta SET meta_value = ‘ Stilettos’ WHERE meta_value = ‘Heels’;

    What happens is that:
    – it reflects correctly on frontend from Heels to Stilettos
    – On Admin, where it once said ‘Heels’ it is now blank/no option chosen. It didn’t change to ‘Stilletos’
    – So when using the search filters, because nothing is selected on admin, the updated ad doesn’t show up in the relevant results.

    I then noted that perhaps its because I only managed to change the Value and Not the ‘Text’. Because on the registered data source plugin we input both Text and Value.

    Long story short, kindly could you help me with a sql snippet that I can run that will not only change the value in the front end, but in admin too.

    Thanks

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

    (@gwin)

    Hi,
    i understand that the field you are having a problem with is a dropdown/checkbox/radio (created using Custom Fields extension)?

    If so then what the SQL query changed are the values saved in the database, but it did not change the options available in the dropdown. What you would need to do is go to wp-admin / Classifieds / Options / Custom Fields edit the [adverts_add] form scheme, edit the field and in the field options change the ‘Heels’ value to ‘Stilettos’.

    If the field was added using the Forms API (that is using adverts_form_load) then you would need to make a similar change in your code which creates the dropdown field.

    Thread Starter sellyk

    (@sellyk)

    Hi,

    Yes,exactly. It changed the values in the database but it did not change to reflect in admin dropdown.

    I have very many ads. Is there no way to bulk make the changes in admin without having to do so manually one by one. It would be incredibly tedious.

    I am working with registered data sources plugin. If I change the value via SQL + make sure to register ‘Stiletto’ , is there a way that when i change from ‘Heel’ to ‘Stiletto’, I can also run a query that would then input the correct option in Admin, from the options available in the dropdown?

    I’m just looking for anyway to not have to go make the changes manually one by one.

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i am not sure which plugin do you mean by the “registered data sources plugin”?

    Anyway, there are two cases here depending on how you fill the options:

    1. “I will enter options myself” – changing the options via SQL query only will not be possible since the custom field options are stored as serialized data, so if you change the value only it will break the whole serialized string making it unusable.

    What you would need to do is have some kind of PHP scription which will get the form scheme from the database, unserialize it, update the option and save it in the database again.

    2. “use data source” – if your data source is a taxonomy then you can change the option while editing it from wp-admin panel.

    If you have some custom script with the taxonomy options then you would need to make the change in the script only as the data_source options are not saved in the database anywhere.

    Thread Starter sellyk

    (@sellyk)

    Hi,

    The plugin i am referring to is the one that you advise we create to have registered data sources as documented here: https://wpadverts.com/documentation/custom-fields-paid-addon/

    I’ll use the example thats available in the link above to further explain my dilemma, as I am not getting exactly what you mean.

    So e.g. array(
    “value” => “apple”,
    “text” => “Apple”,
    “depth” => 0,
    ),

    Via SQL I am able to change the value ‘apple’ with
    UPDATE wp_xxxxxx_postmeta SET meta_value = ‘ Red Apple’ WHERE meta_value = ‘apple’;

    This successfully changes all ads that were ‘apple’ to ‘Red Apple’, but only makes the changes on the frontend. So Now when i go to the backend in admin the ads that were ‘apple’ no longer have ‘apple’ selected. There is nothing selected on that field. It did not change from ‘apple’ to ‘Red Apple’ in the backend settings of the ad. This would mean i would have to manually change each ad to ‘Red Apple’ which is incredibly tedious.

    Kindly, I do not want to have to manually change a ton of ads from ‘apple’ to ‘Red Apple’. I want to be able to automatically change them all on the backend too, the same way i made changes to the frontend via SQL.

    Is there a query that can also change ‘apple’ to ‘Red apple’ that would automatically update the ads settings in admin?

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    the query

    
    UPDATE wp_xxxxxx_postmeta SET meta_value = 'Red Apple' WHERE meta_value = 'apple';
    

    will change all the ‘apple’ values to ‘Red Apple’ so as far as the posts data is concerned you have the values changed (as you can see the value in the frontend).

    What was not changed is the available options in Fruit/Apples dropdown, you would need to go to wp-admin / Classifieds / Options / Custom Fields panel edit the [adverts_add] form scheme and add to the Fruit/Apples field a new option only then the dropdown can have an option selected.

    In otherwords this is not the problem with data saved in the database but rather with the options available in the dropdown.

    Thread Starter sellyk

    (@sellyk)

    Hi,

    Thank you for helping me figure out what I was missing.

    Successfully made all the changes I needed to make.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Update Classifieds via SQL’ is closed to new replies.