Skip Navigation

[Resolved] Custom Post Title Returns 'Array Array'

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

Tagged: 

This topic contains 7 replies, has 3 voices.

Last updated by shanaF 9 years, 8 months ago.

Assisted by: Caridad.

Author
Posts
#236784

First and most important, I have no coding experience and my knowledge is limited to copy/pasting codes and make small tweaks.

Goal:
Information submitted using a CRED form to generate a custom post title.

Issue:
When using the below code in the functions.php file in my theme, it outputs "{Spotlight} Array by Array"

I need to figure out how to get it to replace the word array with the data submitted in the CRED form.

 
add_action('cred_save_data', 'build_title', 10, 2);
 
function build_title($post_id, $formdata)
{
if ($formdata['id']==8930)
{
$field1=get_post_meta($post_id, 'book-title');
$field2=get_post_meta($post_id, 'author');
 
$post_title="{Spotlight} $field1 by $field2";
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title));
}
}

If I add ", true" as shown below, the output post title ignores these fields altogether

$field1=get_post_meta($post_id, 'book-title');
$field2=get_post_meta($post_id, 'author');

Could someone please tell me where I have gone wrong and how to resolve this?

#236785

OOPS, forgot to change the 2nd snippet. It should show as:

$field1=get_post_meta($post_id, 'book-title', true);
$field2=get_post_meta($post_id, 'author', true);
#236937

Dear Shana,

When you are submitting a CRED form, you don't have the data saved yet, so you can't use get_post_meta like that. I assume you have added a generic field (in case of normal Types fields don't forget to add the wpcf- prefix!).

To get the submitted data:

$field1 = $_POST['field-name'];

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Paweł

#237111

I actually figured thatpart out last night, however, now I am in need of adding al the new post types I created to the existing categories display. I generated a new post (one of my new post types) and selected a category.

However, my site is not counting anything I add with a custom post type as an actual post and they are not displaying under recent posts, category lists, or on the home page thumbnails.

How do I tell WordPress to count these new post types as an actual post and add them to the list?

Example, if you look at my site hidden link you will see category listings on the left sidebar. I added a new spotlight post this morning (hidden link) and it is not displaying under the Spotlights archive list, or in the thumbnail gallery of posts.

How can I associate my post types to be included in the existing wordpress categories?

#237113

Amending that last issue...I was able to get them into the archives, but not on the home page

#237477

Dear Shana,

By default WordPress is only displaying regular posts on your home page. To change this you can follow these steps:

- You can create a View thats shows all the posts types you need
- Adjust the layout for this view to display like your home page does
- Insert the shortcode for this View into a page called “Home??.
- Finally, set this page as the home page in Settings -> Reading.

I would also like to tell you that Types uses the wpcf- prefix internally, so some function parameters require this:

$field1=get_post_meta($post_id, 'wpcf-book-title', true);
$field2=get_post_meta($post_id, 'wpcf-author', true);

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards
Caridad

#238919

Before I attempt that, is this just the body of the homepage? How will my other elements (header, sidebars, footer) be affected?

#238974

Fixed using other methods

The forum ‘Types Community Support’ is closed to new topics and replies.

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