Skip Navigation

[Resolved] Target specific article with a formgroup

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 8 replies, has 2 voices.

Last updated by patrickR-3 2 months ago.

Assisted by: Minesh.

Author
Posts
#2778253

I created a CPT called [grundeinstellung] where I store data that repeats across the entire website, such as phone numbers, social media, etc. Then, I created a custom field group that represents the necessary fields in the CPT. I was able to create an article, enter the data there, and retrieve it by ID from that article.

Now, I would like to store multiple articles with various settings in this CPT. Meaning: ID:1 outputs field group 1, ID:2 outputs field group 5, etc. Unfortunately, in the conditional settings, there is no option to target a specific article. Is there a code or workaround for this, or do I need to create a separate CPT for each such settings page?

#2778257

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you can use the conditional block or conditional shortcode to check custom field or shortcode value.

Please check the following Doc:
- https://toolset.com/2021/08/5-advanced-uses-of-toolsets-conditional-block-in-wordpress/
- https://toolset.com/course-lesson/using-toolset-conditional-block/

Using legacy conditional shortcode:
- https://toolset.com/documentation/legacy-features/views-plugin/#conditional-output-in-views

#2778271
toolset-1.jpg
toolset-2.jpg

I know that i can do this inside the article or page but I am trying to assign different custom field groups to different articles in the same CPT.

#2778293

Minesh
Supporter

Languages: English (English )

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

There is no such feature available.

But you can workaround it by adding admin_head hook.

Please check the following related ticket:
- https://toolset.com/forums/topic/wp-admin-how-to-hide-certain-custom-field-inputs-based-on-post-id/#post-1433805
- https://toolset.com/forums/topic/how-do-i-make-a-post-field-group-display-only-for-posts-with-a-given-parent/#post-576550

You can adjust the code as required based on your article ID.

#2778312

I tried to replicate the code with the following function but sadly it isn't working. Also I haven't found the slug of a fieldgroup so i added the ID.
function func_remove_field_groups_for_grundeinstellung() {
global $post_type;
global $post;

if ($post_type == 'grundeinstellung' && isset($post->ID)) {

if ($post->ID == 21) {

$meta_boxes = [
'wpcf-group-cpt-78'
];

foreach ($meta_boxes as $meta_box) {
if ($meta_box != 'wpcf-group-cpt-20') {
remove_meta_box($meta_box, $post_type, 'normal');
}
}
}
}
}
add_action('admin_head', 'func_remove_field_groups_for_grundeinstellung');

#2778347

Minesh
Supporter

Languages: English (English )

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

Can you please share problem URL and tell me on what post ID you want to display what custom field group and what custom field group should not be not display.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2778774

Minesh
Supporter

Languages: English (English )

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

Unfortunately - when I try to login to wp-admin using the admin access details you shared it wont allow me to login to admin.

Can you please send me working admin access details.

I have set the next reply to private which means only you and I have access to it.

#2778785

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I see you added the following to the custom field group's "Data-Dependent" tab that is available when you click on "Edit" button on your custom field group screen:
=> hidden link

($(form_data['id']) eq 21)

I've removed the above code you added and I can see it working as expected.

#2778818

Sorry, I doublechecked this time