Tell us what you are trying to do?
I'm trying to make a custom post title based on answers.
The only thing that's not working is the relationship item isn't populating. So either I don't know the proper syntax or I'm thinking about relationships incorrectly.
In this particular case I want the title of the product registration to show the type of product (which is working) AND the model number (post title) for the child item of a related post type. The title of the image attached should be approximately "subwoofer 512d"
An example of the syntax I'm thinking I may have wrong is "wpcf-@product-registration-subwoofer.child" ... but you can see the full function below for context.
Is there any documentation that you are following?
I found very helpful custom title post documentation (thank you), but nothing that references relationships.
FULL FUNCTION FOR CUSTOM TITLE - >
add_action("cred_save_data", "prodreg_save_data_action",10,2);
function prodreg_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data["id"]==1048)
{
if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-amplifier.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-amplifier.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-subwoofer.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-subwoofer.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-speaker.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-speaker.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-enclosure.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-enclosure.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-signal-processor.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-signal-processor.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-install-accessory.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-install-accessory.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else if (isset($_POST["wpcf-type-of-product-register"]) && isset($_POST["wpcf-@product-registration-lifestyle-gear-item.child"]) ){
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-@product-registration-lifestyle-gear-item.child"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
else {
$name = $_POST["wpcf-type-of-product-register"]." ".$_POST["wpcf-model-number-product"];
// Update the post into the database
$prodreg_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $prodreg_post );
}
}
}
We cannot assist custom coding at Toolset Support - please see https://toolset.com/toolset-support-policy/.
The code you show above is several lines of non-Toolset API code, which we cannot help with.
I see you use Toolset Fields - but the code itself is not related to Toolset, it's using WordPress API and generic PHP.
As you surely understand our API is just a set of hooks and filters to let you add your own custom code, such as you did above.
We can however not assist code within those functions you hook.
Related to the issue you see, that "relationship item isn't populating", I can give some help:
1. To set or get Relationships with code you can use the Toolset Relationships API shown here https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
2. In your code you do not use that API neither to set or to get relationships, you seem to plan accessing the $_POST of the form.
If you want to get the related posts from the chosen value of the related posts select2 Selector in Toolset Forms, you need to access the valid HTML entities, which are to be obtained from the console, for example.
See enlace oculto
For example for a Select2 Parent Post Field in a Form it can be $_POST["@post-page_parent"] (Relationships between posts and pages, one to many).
I found that for some reason the Select2's name is replacing the dot with a undesrcore, so you can get the proper name of the input with this process:
- either open the console and find the input name, replace the dot with an udnerscore and use that
- or, simply var_dump() the $_POST in the Form and see the precise name of all and every $_POST item.
I hope that helps!
PS I assume you'll need to use something like $_POST["@product-registration-lifestyle-gear-item_child"] in your case. Notice I removed the prefix and changed dot to underscore.
"Notice I removed the prefix and changed dot to underscore" -> Exactly the syntax information I was looking for, got it working. Thank you!
My issue is resolved now. Thank you!