Advertisement:

Author Topic: Replace word  (Read 951 times)

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Replace word
« on: October 09, 2018, 07:18:07 am »
Hey,
I want to replace the data input of custom-fields.
For example, when a user put "red" for custom-field1, i want to add "-color" to that and make it: "red-color"
Custom-field1-value = custom-field1-Value . "-color"
And be multiple to do the same thing for all my 10 custom-fields.
Please help me to do this,
Thanks,
« Last Edit: March 21, 2019, 07:55:40 pm by Sophia_OS »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #1 on: February 05, 2019, 12:19:03 pm »
Is there a solution for this?

Aficionado

  • Guest
Re: Replace word
« Reply #2 on: February 05, 2019, 12:42:33 pm »
Is there a solution for this?

You have bumped 5 topics until now with the same old useless "Is there any solution for this".

Please understand that bumping doesn't help anybody, especially you.

Please respect our community, that we are trying to hard to keep alive.


WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #3 on: February 05, 2019, 11:56:41 pm »
There is a solution to this.  :o

Is there a solution for this?

You have bumped 5 topics until now with the same old useless "Is there any solution for this".

Please understand that bumping doesn't help anybody, especially you.

Please respect our community, that we are trying to hard to keep alive.



Bump actually helped a quite of times because I didn't saw some topics (like this one) before...
« Last Edit: February 06, 2019, 12:02:55 am by patrickFromCroatia »

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #4 on: February 06, 2019, 12:00:57 am »
Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = &s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
    
$dao->dao->query($query);
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.
« Last Edit: March 06, 2019, 11:05:17 am by patrickFromCroatia »

Aficionado

  • Guest
Re: Replace word
« Reply #5 on: February 06, 2019, 12:08:42 am »

Bump actually helped a quite of times because I didn't saw some topics (like this one) before...

Well if you encourage bumping of topics, then i do not know what else to say.

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #6 on: February 06, 2019, 12:20:37 am »

Bump actually helped a quite of times because I didn't saw some topics (like this one) before...

Well if you encourage bumping of topics, then i do not know what else to say.

I don't say it's okay but I don't either say it's bad. Sometimes it helps and sometimes it frustrates all us who try to help.

Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #7 on: February 07, 2019, 10:45:30 pm »
Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = &s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

Thank you very much Patrick,
Im on my phone these days. I will test it and post the result after i reach my pc.
Regards,

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #8 on: February 07, 2019, 10:56:19 pm »

Bump actually helped a quite of times because I didn't saw some topics (like this one) before...

Well if you encourage bumping of topics, then i do not know what else to say.

I don't say it's okay but I don't either say it's bad. Sometimes it helps and sometimes it frustrates all us who try to help.

Regards.

This guy dosnt have a problem with bumping. He has a problem with me. And i dont know why. Several times in the past i asked him not to reply to my posts but he dosnt listen.
« Last Edit: February 08, 2019, 08:24:40 pm by Sophia_OS »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #9 on: February 08, 2019, 08:58:26 pm »
Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = &s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

@patrick
would you please edit this code to:
replace multiple custom-fields values?
And also could put custom-fields values in $query by variable? and get html custom-fields values?
By the way, i tested this code but didn't work.
thanks
« Last Edit: February 11, 2019, 09:25:35 am by Sophia_OS »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #10 on: March 06, 2019, 03:52:01 am »
Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = &s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

@patrickFromCroatia
thank you but your code does not work!

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #11 on: March 06, 2019, 11:05:42 am »
Sorry, I forgot one line. Check the edited post.

Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #12 on: March 08, 2019, 11:35:19 am »
Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = &s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
    
$dao->dao->query($query);
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

did not work!
i put custom-field id (Table: oc_t_meta_fields -> pk_i_id) in here: ($field_id = 5;) and put it in functions.php but did not work!
what i need is when i put for example "blue" in custom-field, it stores in the database "blue+color". it adds 'color' to the end of the word that we enter in.


WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Replace word
« Reply #13 on: March 08, 2019, 08:16:22 pm »
Typo again...
Give this a try.

Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
    
$dao->dao->query($query);
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Replace word
« Reply #14 on: March 09, 2019, 03:22:57 am »
Typo again...
Give this a try.

Code: [Select]
<?php
function wm_item_post_replace_meta_value($item) {
    
$field_id 5// CUSTOM FIELD ID
    
$item_id $item['pk_i_id']; // Get item ID.
    
$dao = new DAO(); // Intialise data access object.
    
$query sprintf('UPDATE %st_item_meta SET s_value = "red_color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s AND s_value = "red"'DB_TABLE_PREFIX$item_id$field_id); // Update.
    
$dao->dao->query($query);
}
osc_add_hook('posted_item''wm_item_post_replace_meta_value');

Regards.

This is the same code that you updated up there!
I tested this and didn't work!  :-\