Skip Navigation

[Resolved] Take the first 150 words of body text

This support ticket is created 3 years, 9 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
- 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 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 10 replies, has 2 voices.

Last updated by junev 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2213583

Tell us what you are trying to do?
Take the first 150 words of body text, and not with the standard WP Text Excerpt which is used already. I have a custom field called introduction which will be added to the view template of the custom post type. When this custom field introduction is empty, I want to display the first 150 words.

What is the link to your site?
hidden link

#2214207

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi June,

Thank you for getting in touch.

In terms of displaying the post content with the first 150 words you can use the function in the link below that this customer provided.
https://toolset.com/forums/topic/limit-post-body-content-by-words/#post-621406

Now to for your custom field you can make use of our conditional statement to check if the custom field is empty.

[wpv-conditional if="(' [types field='my-field'][/types]' eq '' "]
Display some content
[/wpv-conditional]

Please let me know if this helps.
Thanks,
Shane

#2215589

Hi Shane, many thanks for your help. I've added the code to trim the body content provided by your customer but as soon as I add the shortcode [limit_content length="280"], the view doesn't load anymore.

Both the snippets for trimming with char counts and char counts without white spaces fail.

I've also tried adding the shortcode in a normal blog post and the post can't even be saved.

#2215939

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi June,

Thanks for the update.

Would you mind allowing me to have admin access to the website so that I can take a look at this for you.

I've enabled the private fields for your next response.

Thanks,
Shane

#2216245

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi June,

Thank you for the credentials.

However they don't seem to work, can you check if they work on your end and let me know.

Thanks,
Shane

#2216463

Sorry!
I set a new pw and tried it with the new pw. Now it works (at least on my side)

#2216853

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi June,

I'm having a bit of trouble locating the frontend page that you're testing the issue on.

Can you perhaps provide me with a link to the frontend page?

Thanks,
Shane

#2217363

Hi Shane, there's no page or post for that because once the short code is inserted, the page or post just doesn't save. The same also happens if i try to put the short code into a content template view.

It'd be great if this could be solved, otherwise, I'll just go ahead without a custom "excerpt".

Thank you for all your help and patience.

#2217847

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi June,

Quite odd, I did a quick test of the shortcode at the link below.
hidden link

I've added the custom shortcode to the content template below.
hidden link

As you can see at the bottom i've added a conditional block that is checking if the intro custom field is empty and then displaying the contents of the block if it is empty.

What I did was to temporarily remove the field data and then refresh the post on the frontend and it works fine. If there is a specific context that you want to use the shortcode in please let me know.

Thanks,
Shane

#2218145
Screenshot 2021-11-11 at 07.53.58.png

You're awesome, Shane. Thank you!

Though, it's rather strange: i tried to access
hidden link (this is the template for CPT projekt)
and i get "critical err", please see attached screenshot.

Since i can't open the content template for CPT projekt, i think it's probably better, if i don't use the shortcode.

I'm reverting the view template and go ahead without the custom excerpt.

Maybe you want to look into this matter should that also happen to others.

I'm going to close this ticket since i'm not going to use the conditional to check and take the first 150 words of body text.

Thank you again,
June

#2218155

My issue is resolved now. Thank you!