Skip Navigation

[Resolved] Merging two post type

This support ticket is created 3 years, 7 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2108183

I have two identical post types (say) 'import' & 'data', 'import' is for importing to 'data'
I'm using a plug-in to read a CSV into 'import', I wish to use toolset views and a PHP snippet to transform 'import' fields into 'data'
I assume the best way would be a View to loop through 'import' with a nested View finding posts in 'data' (via a common field)

Ive used the following sort of code in the past, which I would call from the nested view:
-----
$post_ID = get_the_ID();
$this_post_address = get_post_meta($post_ID,'wpcf-user-address', true);
....some code
update_post_meta( $post_ID, 'wpcf-range', $a );
-----
which I've used to manipulate a post of one type (ie the 'data' above)

my question is: how do I access (read) the 'import' posts from within the snippet?
perhaps you can point me at existing examples in the documentation
Thanks for your great support

#2108249

Hello,

Toolset Views/Blocks plugins are for displaying data, it is not a good idea to use them to import data.

If you just need to change "import" post into 'data' post, you can setup a post form for editing "import" post, after user submit the form, use action hook "cred_save_data" to trigger a PHP function, in this PHP function, change the current "import" post's post type into "data", more help:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/wp_update_post/

For post type parameter of function wp_update_post(), see the document:
https://developer.wordpress.org/reference/functions/wp_insert_post/
'post_type'
(string) The post type. Default 'post'.