[Resolved] Testing for empty post body

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.

This topic contains 11 replies, has 2 voices.

Last updated by sridharK 6 years, 2 months ago.

Assigned support staff: Adriano.

Author
Posts
#122341

I want to display a hyperlink in a Content Template only if the Post (it's a CPT entry actually) has body.

So I tried the following per some earlier posts on this topic but it does not work. When I use that, strangely, the other shortcode's output (specifically, post thumbnail) disappears from the page.

[wpv-if evaluate="'[wpv-post-body view_template="None"]' != ''"]<a href="[wpv-post-url]">More info</a>[/wpv-if]

So I created a shortcode per Adriano at https://toolset.com/forums/topic/conditional-post-body-breaking-site/ and added this in child theme's functions.php: http://pastebin.com/v5MGmwxm

and used

The value of wpv_getcontent is: [wpv-post-getcontent]

in the Content Template.

It always returns 1 as can be seen at hidden link. Note that "Exterior Item 3" has empty body. wpv_getcontent for this should show 0.

Please advise.

#122568

Adriano
Supporter

Languages: English (English )

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

Dear sridharK,

Look the attached image, it is what I'm seeing.

This shortcode should works.

#122576

Can you please check again? hidden link should work now. I had to deactivate few plugins for the page to load fully.

#122648

Adriano
Supporter

Languages: English (English )

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

Dear sridharK,

Please let me see the code that you are using in this View.

#122703

Sure.

At Views > Settings: hidden link

View summary: hidden link
View detail: hidden link

Content Template summary: hidden link
Content Template detail: hidden link

Relevant code in child theme's functions.php: hidden link
Full code in child theme's functions.php: hidden link

Portfolio CPT entry titled "Exterior Item 3": hidden link

If you need WP login, please let me know your email address to send to.

#123198

Adriano
Supporter

Languages: English (English )

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

Dear sridharK,

Please try to replace the code below:

add_shortcode ( 'wpv-post-getcontent', 'wpv_getcontent' );
function wpv_getcontent() {
	if(get_the_content() != '') :
		return 1;
	else :
		return 0;
	endif;
}

With:

add_shortcode ( 'wpv-post-getcontent', 'wpv_getcontent' );
function wpv_getcontent() {
	if(get_the_content() != '') :
		return 1;
	else :
		return 0;
	endif;
        wp_reset_query();
}

If it didn't make difference please provide the credentials, I will take a look at it (adriano.f@onthegosystems.com)

#123226

Tried and it didn't make a difference. Sent you a mail.

#124151

*bump*

#125158

Adriano
Supporter

Languages: English (English )

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

Dear sridhark,

My apologies for the delay. I'm checking my custom shortcode, it should works propetly, I don't know which is breaking it. I will need more time to check this one. Thank you for your understanding.

#125509

Adriano
Supporter

Languages: English (English )

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

Dear sridhark,

The get_the_content() doens't work in this case, so I've replaced it with $post->post_content and it looks like works.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

#125591

Thank you. It works.

#125854

Published about this here: hidden link