Skip Navigation

[Resolved] Selecting published post from POST TYPE 2 when Editing POST TYPE 1

This thread is resolved. Here is a description of the problem and solution.

Problem:
I need a way to select already created posts of a specific post types limited to 5 selections (5 dropdowns would work)
Solution:
Solution here:
https://toolset.com/forums/topic/selecting-published-post-from-post-type-2-when-editing-post-type-1/#post-617366
Relevant Documentation:

This support ticket is created 6 years, 10 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#616707

I have the following structure:

I have a Post Type 1 called "Collection" with actually no posts

Then I have a secont Post Type 2 called "Item" which will get posts only published by admins. An item has various custom fields in it.

I now want to be able to let user select 5 posts of "Item" when creating a "Collection".

For CRED: I need a way to select already created posts of a specific post types limited to 5 selections (5 dropdowns would work)

For VIEWS: I need to show the selected posts of Item inside a collection loop with all custom fields of items.

For LAYOUTS: I need to show the fields of "items" in "collection"

it that possible to achive?

#616769

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Holger,

Thank you for contacting Toolset support. I am sorry but this is not possible using built-in Toolset features

But if you want to give it a try with custom solution then please note this requires a custom code or modifications which falls into Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thank you

#616774

I am shocked about your answer. In toolset blog where you will find a very close to finish development note about that.

You tried to sell a custom development for something that is already on the Roadmap and soon available for everyone.

No thanks.

#616840

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Holger,

I am sorry if you are not satisfied with my answer. May be I am not getting your requirement, can you please point me to the link where you see this in Toolset blog.

Thank you

#616898

I think it´s here:

https://toolset.com/2017/12/types-and-views-betas-with-many-to-many-relationships/

This allows to select posts related to another post (in my case: items related to collection.

I am not sure if CRED already can handle this, but it seems to be planned

#617366

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Holger,

You can create one-to-many relationship ‘Collection’ will be parent and ‘Item’ will be child.
https://toolset.com/documentation/beyond-the-basics/post-relationship-concepts/implementing-one-to-many-relationships/

For creating 5 dropdown of child posts using custom code, and code will be something like this:

/**** Create custom shortcode [child_post_select] ****/
function child_post_select_func(){
    
    $args = array(
        'post_type' => 'child-cpt-slug', // Child CPT slug
        'nopaging' => true
    );
    // Return an array of all posts
    $posts_list = get_posts($args);
 	
	$content = '<select name="child_dropdown_1" class="form-control" output="bootstrap" required="required">';
			$content .= '<option>--- Choose your add ---</option>';
			foreach ($posts_list as $post) :
				$content .='<option value=' . $post->ID . '>' . $post->post_name . '</option>';
			endforeach;
	$content .='</select>';
	wp_reset_postdata();
	return $content;
}
add_shortcode( 'child_post_select', 'child_post_select_func' );

2. After that you can add following shortcode in the form:

[child_post_select]

3. Then saved parent ID on form submit using cred_save_data hook and this code:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

add_action('cred_save_data', 'prefix_cred_save_data_action', 10, 2);
function prefix_cred_save_data_action( $post_id, $form_data ){
    if ($form_data['id']==123){ //do the following code only if the CRED form ID is 123, adjust this to your CRED form ID
        if (!empty($_POST['child_dropdown_1'])){ //if child is selected
            $child_id = $_POST['child_dropdown_1'];
            add_post_meta($child_id, '_wpcf_belongs_parent_id', $post_id, true); //save the ID of the current post in child field
        }
    }
}

Here is doc to display child post content on parent pages:
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
https://toolset.com/documentation/user-guides/displaying-related-child-posts/

Thank you

#619426

Thanks. It´s solved with a multi select dropdown relationship field