• Resolved falcobus

    (@falcobus)


    Hi, when I add an new ad, I need for input text Location (adverts_location) to delete the first 4 chars – substr ($ location, 3), before inserting in the database. How should I do it?

    For example: i write Location: AUSTRALIA and click to preview and click to SEND. Now, i need delete first 4 chars (leave AUST, stay RALIA, before inserting in the database.

    Thanks

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

    (@gwin)

    Hi,
    if you want this to happen after preview and only when adding an Ad using [adverts_add] shortcode then you can add the code below in your theme functions.php file to do it

    
    add_action( "wpadverts_advert_saved", function( $post_id ) {
      $loc_cut = get_post_meta( $post_id, "_location_is_cut", true );
      if( $loc_cut == "1" ) {
        return;
      }
      $location = get_post_meta( $post_id, "adverts_location", true );
      $location = substr( $location, 3 );
      update_post_meta( $post_id, "adverts_location", $location );
    } );
    
    Thread Starter falcobus

    (@falcobus)

    Hi Greg, thanks, it s working perfect, when I add a new ad.

    But if i want editing ad, Location stay without change. What I must to do if I want delete first 4 chars also when ad is editing?

    Thanks

    Plugin Author Greg Winiarski

    (@gwin)

    I suppose this will generate unpredictable results, when user will post from [adverts_add] location “Australia” it will be saved as “ralia” and when he will edit the Ad from [adverts_manage] page without updating the location it will be cut to just “a”, so in order to have the location stay as “ralia” the user would need to change it first to “Australia”.

    Either way, right now the [adverts_manage] shortcode does not support the wpadverts_advert_saved action so i am afraid it is not possible to apply this when updating an Ad at least not without modifying the original source code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Delete chars from Location’ is closed to new replies.