Skip Navigation

[Resolved] Manage with types not working as expected

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

Problem:
The customer's theme has a custom field for Taglines, he went to Post Field Control and set it to "manage with types" but the content will not appear on the front-end:
Solution:
The option Manage with types will allow you to use that custom field inside a Toolset custom field group, but it won't automatically link it to the custom field available inside the custom theme or plugin.

Upon further review, that fields was serialized by the theme and placed inside a 'lp_listingpro_options' option. I had to use custom code to retrieve this field. I added it to a shortcode and registered the shortcode within Toolset settings, then the field managed by the theme became available to be used in the front end as well. The shortcode was this:

function my_shortcode_callback( $atts ){    
    // Get the tagline from post_meta
    $myvals = maybe_unserialize(get_post_meta($atts['post_id'], 'lp_listingpro_options'));
    return $myvals[0]["tagline_text"];  
}
add_shortcode( 'tagline_text', 'my_shortcode_callback' );

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://wp-staging.com/serialized-data-wordpress-important/
https://wpengine.com/support/wordpress-serialized-data/
https://deliciousbrains.com/wp-migrate-db-pro/doc/serialized-data/
https://developer.wordpress.org/reference/functions/maybe_serialize/
https://developer.wordpress.org/reference/functions/maybe_unserialize/

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 14 replies, has 2 voices.

Last updated by Timothy 7 months, 2 weeks ago.

Assisted by: Mateus Getulio.

Author
Posts
#2691390

I have a theme that has a single line custom field for Taglines, its key is listingproc_tagline. In Post Field Control I have set it to "manage with types" and have used this shortcode [wpv-post-field name="listingproc_tagline"] but the content will not appear on the front-end:

hidden link

I followed another post and added this custom field to an existing custom field group, but this just creates a new custom field so I'd have to reenter all the text into that which just defeats the purpose.

#2691476

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Can you please try adding the prefix wpcf- to see if it brings any data?

[wpv-post-field name="wpcf-listingproc_tagline"]

If it doesn't help, I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

**IMPORTANT**

- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link

Please, let me know if you need any additional details. Have a nice day.

#2691610

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

tagline.png

Hello there,

Thank you for sharing that access.

I created a separate custom field group for the tagline, I assigned it to the Listings CPT as well so it now has 2 groups.

I changed the assignment of the custom field listingproc_tagline to the new group, letting it isolated in the new group I created.

Now when I checked the view you created, it is showing the content from this custom field, I edited it to 'test 2' just to confirm it is reflecting the changes.

Can you please check if it is working as expected now?

Thank you, please let us know.
Mateus

#2691625

But I thought the point of "manage with types" meant that whatever content is in the original field could now be accessed with a types shortcode. I don't want a spearate/new field, I want to access the content that is in the original field.

hidden link

#2691668

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

The function manage with types is for when you have a custom field registered elsewhere but you want Types to take over and use its own version of that custom fields. It is slightly different from what you need.

I checked it and in your case that text in the last screenshot was coming from a serialized post_meta under 'lp_listingpro_options'.

What you can do to access it with Views, is to retrieve its value using a shortcode, register this custom shortcode and use it within views.

I implemented a demonstration for you.

Inside your theme's function.php file I created the shortcode 'tagline_text':

function my_shortcode_callback( $atts ){    
    // Get the tagline from post_meta
    $myvals = maybe_unserialize(get_post_meta($atts['post_id'], 'lp_listingpro_options'));
	return $myvals[0]["tagline_text"];	
}
add_shortcode( 'tagline_text', 'my_shortcode_callback' );

In the code above, it gets the post_id passed as a param to the shortcode and return the tagline.

Then I went to Toolset > Settings > Front-end content > Third-party shortcode arguments and added the new shortcode I created tagline_text.

Finally, I went to the view 1 Listing Header Section and used the shortcode passing the current post_id of the loop as argument:

[tagline_text post_id="[wpv-post-id]"]  

When I check that view now, it seems to be pulling the data correctly from the Business Tagline Text fields.

Please note: the code provided is to be used as an informational one. remember that custom coding is out of the scope of our support so we can't create, debug or modify code for you and it's your responsibility to maintain it. we hope the one we used as an example could point you in the right direction.

Please give it a check if everything is working as expected now.

Best,
Mateus

#2691714

Excellent, yes this is exactly what I needed, I appreciate the custom code you wrote. Final question, how did you find that text was "coming from a serialized post_meta under 'lp_listingpro_options" in case I want to create other shortcodes for other custom fields from the theme.

Tim

#2691880

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Tim,

I created a temporary test view and added it to a draft page. In this view I added another custom shortcode where I just echoed out the contents of the post_meta of the same Listing ID you used in your view 1 Listing Header Section(post id: 26992):

Eg.:

function my_shortcode_callback( $atts ){    
    return get_post_meta(26992); 
}
add_shortcode( 'test_shortcode', 'my_shortcode_callback' );

When you call the function get_post_meta with only the post ID, it returns all post meta data: https://developer.wordpress.org/reference/functions/get_post_meta/.

Then, when I accessed the view results, I was able to see how the post meta was set up and spotted that I needed to unserialize the data.

Best regards,
Mateus

#2691901

Sorry, I don't understand what "unserializing the data" means , I tried to recreate that test_shortcode to see exactly what you mean but nothing outputs except the word "array".

And if I want to do the same thing for another custom field from this theme, like price, do I just recreate the shortcode with the post_meta of that field, and then it here to Toolset > Settings > Front-end content > Third-party shortcode arguments.

Tim

#2691909

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Tim,

I understand your concerns and appreciate your patience as we navigate this issue together. It's important to clarify that the matter at hand isn't directly related to Toolset functionalities. WordPress employs a specific method for storing data, which is actually quite complex and worth understanding in depth. While I've found some resources that could shed light on this, such as these articles on serialized data in WordPress, the crux of the situation seems to stem from how your theme manages its custom fields:

hidden link
hidden link
hidden link
https://developer.wordpress.org/reference/functions/maybe_serialize/
https://developer.wordpress.org/reference/functions/maybe_unserialize/

Toolset is designed to enable you to work efficiently with custom fields created within our ecosystem. When it comes to custom fields generated by third-party themes or plugins, the integration often requires a more tailored approach. This is why I provided a custom code snippet to help bridge this gap, aiming to guide you towards a potential solution.

However, I recognize that implementing custom solutions might not be straightforward for everyone. If you find yourself needing more hands-on assistance, our Toolset Contractors are well-equipped to offer their expertise. They can provide personalized support to ensure your project's success, navigating through challenges like these with ease: https://toolset.com/contractors/

Please feel free to reach out if you have any more questions or if there's anything else I can do to assist.

Kind regards,
Mateus

#2691913

Thanks, the shortcode you created works fine. I appreciate that. I was just curious how I could recreate the test_shortcode shortcode so I could also see the post meta data. I've added that code to the functions file and added the shortcode to the view, but I only see "array"

#2692231

If I recreate the steps you did it should output the post meta right?

hidden link

#2692263

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Tim.

That's correct.

You can use the WordPress function get_post_meta to echo out the meta data of a specific post. You need to specify the ID of the post and the meta key, if you omit the key, it will bring all data that belong to that post.

If you're having trouble echoing the data coming from the array, you might want to use the print_r function to check the array structure:

hidden link

#2692277

Right, I'm trying to output all the meta date that belongs to that post, 26992 by using the shortcode you provided and a test view:

function my_shortcode_callback3( $atts ){
return get_post_meta(26992);
}
add_shortcode( 'test_shortcode', 'my_shortcode_callback3' );

Test View:
hidden link

Output page:
hidden link

But all it is outputting is "array"

#2692283

Basically I want to retrieve that meta data because I've used your shortcode technique to get the address custom field, and this works fine. But when I do the same for the Price custom field nothing is returned, so I'm trying to figure out what I need to adjust in the shortcode code.

#2692456

Can you just verify that this shortcode is correct for outputting all the meta values?

function my_shortcode_callback3( $atts ){
return get_post_meta(26992);
}
add_shortcode( 'test_shortcode', 'my_shortcode_callback3' );