Skip Navigation

[Resolved] Question about default content in custom post type

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 4 replies, has 3 voices.

Last updated by Minesh 6 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2698583

Hello, I have a question that I think is simple. By enabling the visual editor one can write content in the custom post type (which would not be visible in the front-end) but this content is easily recognizable by other plugins

What I would like to achieve is for each custom post type to have as content something like [types field='custom-description' output='raw'][/types]. This way my SEO plugin can collect the first 160 characters as an SEO description

In my particular case, if I put "custom-description" in description I may have descriptions that are too long, that's why I would like to insert it as content for all custom post types

It's possible? Basically I am referring to the description that SEO plugins usually detect and generate automatically (I am working with Rank Math)

Thanks greetings

#2698652

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The question may seem simple, but I'm not quite sure what you mean 🙂

"enabling the visual editor one can write content in the custom post type (which would not be visible in the front-end)"

Let's just be clear about what we mean by content when editing posts.

A post has a title, and it has post content (with the classic editor that is a tinyMCE editor with Visual and Text tabs; with the block editor its where you add blocks, with page builders its where you insert page-builder modules).

When you display such a post on the front end, your theme will almost certainly output the post title, and the post content.

The post may also have custom fields (post meta), which typically are not output by your theme unless you modify the theme to include custom templates, or if you use a visual template editor like Toolset where you might output values of the custom fields.

Now, you talk about default content for a custom post type.

You mean all post types should start with the same content, which can be overwritten? And you are referring to post content, or to custom fields?

You mention a custom-description custom field, but a custom field only applies to a single post, not to all posts of a post type.

I'm sorry, I'm not understanding very well what you are asking, if you could please elaborate.

#2698701
Data on custom post type2.png

I've done more experiments and what I had in mind doesn't work

But I explain it with this image, I simply wanted to place content as a "common post" to a custom post type. Unfortunately Toolset shortcodes don't work, my SEO plugin could only detect the "Plain text" in the example

Before closing the ticket I would just like to know if more people have faced this problem. Simply put, I would just like to know if I can do something so that the SEO plugin recognizes the content of the custom post type (in my case so that it generates an excerpt automatically) or if there is a simple way to insert a custom field as " normal post" (in my case, so that it is treated as the "plain text" of the example)

I know it's a very unconventional approach (obviously I work with the Toolset content template myself). But it may be interesting to select some custom fields to be inserted as a normal post to optimize integration with third-party plugins such as WordPress itself

Thanks greetings

#2698721

I have changed the approach and found a solution to have a suitable excerpt in my situation, but occupying WP_Query

Is there a simpler or lighter way? (I'm working with Rank Math, it doesn't accept shortcodes in meta description)

Thanks greetings
------------
function truncate_custom_field() {
$args = array(
'post_type' => 'tu_custom_post_type', // Important to change
'posts_per_page' => 1,
'meta_key' => 'wpcf-custom-field',
'fields' => 'ids'
);

$query = new WP_Query($args);

if ($query->have_posts()) {
$post_id = $query->posts[0];
$full_text = get_post_meta($post_id, 'wpcf-custom-field', true);
$truncated_text = mb_strimwidth($full_text, 0, 153, '...');

$current_truncated = get_post_meta($post_id, 'wpcf-custom-field-shorter', true);
if ($truncated_text !== $current_truncated) {
update_post_meta($post_id, 'wpcf-custom-field-shorter', $truncated_text);
}
}
}

add_action('init', 'truncate_custom_field');

#2698779

Minesh
Supporter

Languages: English (English )

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

As you are using RankMath and we do not have any integration with that plugin.

In addition to that RankMath uses very specific Javascript to integrate custom fields. Better you may contact RankMath plugin support and check with them if they have any ideas to have better solution compare to what you have currently.

#2698858

Okay, maybe in the future you could consider a way to insert content as a "normal post" in wordpress, it would be an interesting way to optimize with third party plugins and with wordpress itself