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?
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);
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ł
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?
Amending that last issue...I was able to get them into the archives, but not on the home page
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
Before I attempt that, is this just the body of the homepage? How will my other elements (header, sidebars, footer) be affected?
Fixed using other methods