Skip Navigation

[Resolved] Getting a View to display an excerpt and title based on custom fields

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by lilianS-2 4 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1297149

Tell us what you are trying to do?
I have a view that currently displays posts based using the Post Title and an Excerpt. I would like to be able to display custom fields instead of the Title and Post content (or guidance on how to add Title and Content fields to a Post Form).

(This form is a view of posts that various users submit via a Post-Form we use ---> our current post view has custom fields but not one for post title and description. This may be the simplest. How do I add those?)

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1297157

Update: I figured out how to call the fields I need but I am struggling with assigning a post title. I need a way to have the post form (hidden link) define the Post Title (and subsequently the Post URL).

It seems if I do not assign a title and non-generic URL to a post, it breaks the link to view the individual post.
hidden link

See screenshot of error message: hidden link

#1297215

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can use the Toolset Form's API hook cred_save_data to defifne the post title.

For example:

add_action('cred_save_data', 'func_build_custom_post_title', 10, 2);
function func_build_custom_post_title($post_id, $form_data) {
 
if ($form_data['id']==1259) {

$title= get_post_meta($post_id, 'wpcf-listing-title', true);
  
$post_title=$title;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));

}
}

More info:;
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1297225

Thank you! I will test.

I am plugging this into my functions.php file. I received a syntax error upon pasting that code: hidden link

What should I change?

#1297229

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I do not know from where you are trying to copy the code I shared as the quotes are changed to htmlentities.

Please use the following code:

add_action('cred_save_data', 'func_build_custom_post_title', 10, 2);
function func_build_custom_post_title($post_id, $form_data) {
  
if ($form_data['id']==1259) {
 
    $title= get_post_meta($post_id, 'wpcf-listing-title', true);
   
    $post_title=$title;
    $slug = sanitize_title($post_title);
    wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
 
}
}

Please make sure you are using correct code. The field should look like 'wpcf-listing-title' (with single quotes).

#1297231

Yes, I tried adding that function and it disabled the site so I removed it. Please advise!

#1297233

Thank you! I had copied it from the email not the forum, that's where the HTML came from

#1297235

My issue is resolved now. Thank you! 😀

#1297237

I have a follow up question, I worked with a support member earlier via chat, but the solution wasn't quite complete. There are check boxes on our post form that are supposed to define post category, but it does not seem to do that (when I submit the post, if I check it on the back end it is "Uncategorized" rather than assigned our custom taxonomies. Is there pHp I should add for that as well?

#1297239

I require additional assistance on this post form

#1297245

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.