Osclass forums
Development => Development => Topic started by: Sophia_OS 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,
-
Is there a solution for this?
-
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.
-
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...
-
<?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.
-
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.
-
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.
-
<?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,
-
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.
-
<?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
-
<?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!
-
Sorry, I forgot one line. Check the edited post.
Regards.
-
<?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.
-
Typo again...
Give this a try.
<?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.
-
Typo again...
Give this a try.
<?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! :-\
-
@patrickFromCroatia
I tested your code but it really didn't work!
I edited my first post for clarifying my question!
Thanks,
-
I will try the code on my demo site.
One suggestion: please don't expect EVERYTHING from others, try enabling PHP debugging, SQL debugging, testing, looking at tutorials etc. That way you will learn and it will be better than just copying the code.
Regards.
-
Just tried the code. It worked.
http://148.251.207.178/osclass/plugins/demo/index.php?page=item&id=102
I selected "red" and "red_color" was saved in the database.
Regards.
-
Just tried the code. It worked.
http://148.251.207.178/osclass/plugins/demo/index.php?page=item&id=102
I selected "red" and "red_color" was saved in the database.
Regards.
Not like that. Please reread my first post. I edited it!
I dont want just replace red with red_color. I want to add "_color" to the value of custom-field. And also for multiple custom-fields not just one. Please read my first post again. Its edited!
Thank you Patrick,
-
Just tried the code. It worked.
http://148.251.207.178/osclass/plugins/demo/index.php?page=item&id=102
I selected "red" and "red_color" was saved in the database.
Regards.
Not like that. Please reread my first post. I edited it!
I dont want just replace red with red_color. I want to add "_color" to the value of custom-field. And also for multiple custom-fields not just one. Please read my first post again. Its edited!
Thank you Patrick,
@patrickFromCroatia
Patrick, did you read this post?
-
Look, I can help but I can't write all the code. You have a lot of questions and expect people to write all the code for you. There's a job section for that. I work on a lot of paid projects and I don't have time, can't and don't want to do everything in cases like this...
Anyways, make an array of colors and use foreach to replace each one of them, or look if there is a SQL query to replace more stuff, I have no idea. Not sure how fast is this, but it probaby can be optimized...
<?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.
$colors = array('red', 'blue'); // List of colors.
foreach($colors as $color) {
$query = sprintf('UPDATE %st_item_meta SET s_value = "%s-color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s AND s_value = "%s"', DB_TABLE_PREFIX, $color, $item_id, $field_id, $color); // Update.
$dao->dao->query($query);
}
}
osc_add_hook('posted_item', 'wm_item_post_replace_meta_value');
Regards.
-
Look, I can help but I can't write all the code. You have a lot of questions and expect people to write all the code for you. There's a job section for that. I work on a lot of paid projects and I don't have time, can't and don't want to do everything in cases like this...
Anyways, make an array of colors and use foreach to replace each one of them, or look if there is a SQL query to replace more stuff, I have no idea. Not sure how fast is this, but it probaby can be optimized...
<?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.
$colors = array('red', 'blue'); // List of colors.
foreach($colors as $color) {
$query = sprintf('UPDATE %st_item_meta SET s_value = "%s-color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s AND s_value = "%s"', DB_TABLE_PREFIX, $color, $item_id, $field_id, $color); // Update.
$dao->dao->query($query);
}
}
osc_add_hook('posted_item', 'wm_item_post_replace_meta_value');
Regards.
@patrickFromCroatia
Thank you very much, this works now! but there is one problem! i want to add '-color' to custom-field's value! i want to get the value of custom-field and add '-color' to it!
please see this code:
<?php
function wm_item_post_replace_meta_value($item) {
$field_id = 5;
$item_id = $item['pk_i_id'];
$dao = new DAO();
$cf_value = Params::getParam('meta[24]'); //Not working! i can not get the value of custom-field!
$query = sprintf('UPDATE %st_item_meta SET s_value = "%s-color" WHERE fk_i_item_id = %s AND fk_i_field_id = %s', DB_TABLE_PREFIX, $cf_value, $item_id, $field_id);
$dao->dao->query($query);
}
osc_add_hook('posted_item', 'wm_item_post_replace_meta_value');
-
I'm on phone, but try Params::getParam('meta')[24]
Regards.
-
I'm on phone, but try Params::getParam('meta')[24]
Regards.
Thank you very much Patrick!