Site logo

Archived topic

Getting filter to work in elements

12 replies · Started by John on July 30, 2022

Viewing posts 1–13 of 13

Good Morning,

I have created a custom post type and need entire post to show on the archive and related taxonomy pages but I also need just the excerpt on my normal posts, so I have that set in the GP customizer.

I found this filter:

add_filter( 'generate_show_excerpt','tu_full_post_search' );
function tu_full_post_search( $show_excerpt )
{
if ( is_search() )
return false;

return $show_excerpt;
}

So figured, (maybe stupidly) that I could add it in with an elements hook and then tell it only to work on those pages. However, when I try that the code shows on the front end and does not execute. I have tried it hooked in several different places and I have checked the box to say it's code.

Are filters just not supported in elements, or am I doing something stupid?

I could put it in the child functions file with an if statement to check the post type, but I'm not sure where I would hook on the resulting function.

Thanks
John

Hi Again,

OK, found another entry that says filters don't work in elements. Fair enough.

So now I'm trying to get it to work in my functions file, but no luck.

Now working on my staging site: https://staging-morganscloud.kinsta.cloud/tips/

This is what I have so far, but it does not change the tips archive to full content. Any pointers would be much appreciated.

add_filter( 'generate_show_excerpt','tu_full_post_search' );
function tu_full_post_search( $show_excerpt )
{
if ( is_post_type_archive('tips')){

$show_excerpt=false;

return $show_excerpt;}
}

Intersecting thing is that just this changes the posts screen to full content but not the custom post tips:
add_filter( 'generate_show_excerpt','tu_full_post_search' );
function tu_full_post_search( $show_excerpt )

$show_excerpt=false;

return $show_excerpt;
}

Hi there,

are you using a Block element Content Template ?

IF so you can create one specifically for your CPT, and the use the Core Content Block to display the post content instead of the excerpt.

Hi David,

Never done that before, but it sounds like a great way to solve it. I will dig in.

Big thank you for coming up on a holiday weekend. You guys are the best.

Hi Again David,

Sorry, but two more issue.

It works but I can't get the images to show when I insert a query block (either the GP one or the standard WP) when it
it's on an elements block page : https://www.morganscloud.com/jhhtips/

But it works fine if I just use it on a standard page: https://www.morganscloud.com/johns-tips-tricks-and-thoughts-2-1/

I wish I could use a standard page but I need an RSS feed and the breadcrums to take readers back to the archive for the CPT

The other thing is that on the elements page the posts are repeating three times

Any pointers would be much appreciated.

John

Hi Again,

OK, I figured out why the images were not displaying: something stupid I did years ago in CSS. I can fix that.

But I'm still perplexed by why the posts are showing three times: https://www.morganscloud.com/jhhtips/

Again it might be something stupid I'm doing, but if you have any pointers on where to look I would appreciate it.

Thanks
John

Hi Yet Again,

Oh dear, it looks like I can't use the query loop on a archive template: https://generatepress.com/forums/topic/archive-page-with-query-loop-added-via-content-element-displays-posts-repeatedly/

Has that been changed/fixed in some way, since I think that's what you recommended above. Or did I just misunderstand.

Anyway, looks like I'm back to square one and need to figure out how to force the tips archive to show the entire content while the normal posts just show excerpts.

Any advice appreciated.

John

You don't use a Query Loop, in the Block Element - Content Template, as youre adding a Loop inside a Loop :)

1. Create a new Block Element,
2. Set the Element Type to Content Template.
3. There is a list of Templates to choose from, select one for a quick start.
4. Inside the template you just added, insert a Content Block.
5. Set the Display Rules to apply to the relevant archive.

Hi David,

I only have one thing to say....Duh!

Why didn't I think of that...don't answer that.

I need to dig-way deeper into all the cool stuff GP does, a particularly since I suck as a coder.

Seriously, thank you!

You're welcome - and we are looking at ways to make this kind of thing way more accessible, as today they are complicated things to work with :)

Hi David,

The key thing is that I have been in WP for 15 years so I tend to fall back on code, even though I suck as a coder, and not realize that there are easy, but still light, ways to do things without code. The other thing is I kinda thought that the standard block editor would give me everything I needed without realizing how far ahead generate blocks/elements is. Just about to buy pro, now I know better.

And the final point I learned is that GB support's most valuable attribute is not "this is how to do it" but rather "wait, here's a better way". That's priceless for someone like me who is primarily a content creator with a business to run (membership) not a developer.

Thanks again.

Thank you for your kind words John, it really is appreciated, and it always make me happy to hear we are getting things right!

Have a great day!

This archived topic is closed to new replies.