Skip Navigation

[Resolved] Out put post-specific custom field data in sidebar

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

Last updated by katrina 7 years, 11 months ago.

Assigned support staff: Caridad.

Author
Posts
#115613

Hello,

I have a custom post type for which I've created two custom field groups. The first custom field group is for content that gets displayed in the body of the post. I'd like the second custom field group to display its content in the sidebar. I'm having some trouble with that...

I tried a tip from another thread (https://toolset.com/forums/topic/custom-field-group-in-sidebar/), but it's not quite working.

I installed the Enhanced Text Widget plugin, and in my sidebar, dragged in the widget and entered the following:

<?php // display custom fields
global $wp_query;
$postid = $wp_query->post->ID;
echo 'Hello World!'; // testing to see if this enhanced text widget actually parses php!
echo $postid; // yep, getting the correct ID
?>
<hr>
<a class="more" href="#">View More Impact Stories</a>
<hr>
<div class="featured-strip">
[sidebar-posts-featured-img-caption type="impact-story" qty="3"]
</div>
<-- display Types custom fields -->
[types field="donate-text" class="" style=""][/types]
<a href='[types field="donate-button-url" raw="true"][/types]'>[types field="donate-button-title" class="" style=""][/types]</a>
<hr>

In my sidebar, the 'Hello World' shows up, so I know php is getting parsed there.
I also get the correct post ID.
But, the custom fields aren't being displayed.

What am I missing?

Thanks,
Eric

#116082

Hi all,

I posted this Thursday...was hoping to have some feedback by now. You're usually pretty quick. May I please get some help today? Working on a deadline here...

Thanks,
Eric

#116119

Well, I think I solved the problem...

In my sidebar, above the Types custom fields, I have a shortcode that pulls in three featured images from a particular custom post type. Turns out I needed to add wp_reset_postdata(); to the end of that function, then move the sidebar query to directly above the Types custom fields. New code looks like this:


<hr>
<a class="more" href="#">View More Impact Stories</a>
<hr>
<div class="featured-strip">
[sidebar-posts-featured-img-caption type="impact-story" qty="3"]
</div>
<?php // display custom fields
global $wp_query;
$postid = $wp_query->post->ID;
?>
<!--[wpv-post-id]-->
[wpv-if donate_text="wpcf-donate-text" evaluate="!empty($donate_text)"]<strong>
[types field="donate-text" class="" style=""][/types]
[/wpv-if]
[wpv-if donate_url="wpcf-donate-button-url" evaluate="!empty($donate_url)"]
<a href='[types field="donate-button-url" raw="true"][/types]'>[types field="donate-button-title" class="" style=""][/types]</a>
[/wpv-if]
<hr>

Hope this helps someone.

#166230

thanks eric!