Skip Navigation

[Resolved] Only first field shows

This support ticket is created 2 years, 11 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.

Our next available supporter will start replying to tickets in about 1.54 hours from now. Thank you for your understanding.

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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by SteveR6772 2 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2241007

Tell us what you are trying to do? Build content template display custom fields in custom content type.

Is there any documentation that you are following? No

Is there a similar example that we can see? hidden link

Only the first case of using the service field shows the value (the second is simply a duplicate block).
If I move preferred location first, it's value shows and service does not.
(There should also be a number of values under personal information).

I have disabled in caching.

What is the link to your site? hidden link

#2241229

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot this, I'll need to see how these custom fields and the content template are set up, in the admin area.

Can you please share temporary admin login details, in reply to this message?

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2243213

Thank you for sharing these details, but, I'm getting the message:
"Error: The username {*****} is not registered on this site. If you are unsure of your username, try your email address instead."

Can you please check the username and password again?

Note: I've set your next reply as private.

#2244857

The new access details worked.

I've noticed that the select fields "Service" and "Prefered Work Location" are set to use the "wpt_field_options" filter, to programmatically generate the options.

The limitation of using this filter is that the when the value from these fields is shown using the dynamic content option, the output of fields that come after it, is affected.

To overcome this, you can remove the two advanced heading blocks for these fields, and instead add them using the shortcodes in a "Fields and Text" block, like this:


<p><strong>Service:</strong> [wpv-post-title item="[wpv-post-field name='wpcf-requested_service']"]<p>

<p><strong>Preferred Location:</strong> [wpv-post-title item="[wpv-post-field name='wpcf-prefered-work-location']"]</p>

I hope this helps and please let me know if you need any further assistance around this.

#2245569

Has this bug been reported or should I?

Thanks

#2245793

Thanks for writing back.

During some further tests, it emerged that the use of "WP_Query" in the plugin file "service-requests.php" is responsible for this unexpected behavior.

In this file, the "WP_Query" function is being used for generating the options for the fields "Service" and "Prefered Work Location" fields, which interferes with the main query/loop of the page too.

Instead of using the "WP_Query" function, you can use the "get_posts" function.
( ref: https://developer.wordpress.org/reference/functions/get_posts/ )

Here is how the updated function "service_requests_possible_services" for the "Service" field will look like:


add_filter( 'wpt_field_options', 'service_requests_possible_services', 10, 3);
function service_requests_possible_services( $options, $title, $type ){
	switch( $title ){
		case 'Service':
			$options = array();
			$options[] = array(
				'#title' => 'Please Select Service',
				'#value' => 0
			);
			$args = array(
				'post_type'        => 'service',
				'posts_per_page'   => -1,
				'post_status'      => 'publish',
				'orderby' => 'title',
				'order' => 'ASC',
			);
			$posts_array = get_posts( $args );
			foreach ($posts_array as $post) {
				$options[] = array(
					'#value' => $post->ID,
					'#title' => $post->post_title,
				);
			}
		break;
	}
	return $options;
}

Similarly, you can update the function "service_requests_possible_locations" for the field "Prefered Work Location" too.

#2246229

My issue is resolved now. Thank you!