Archived topic
generate_before_entry_title not working in WP Query loop
6 replies · Started by Germaine on January 18, 2021
Hi guys,
When I'm trying to loop through posts on the homepage with code in a custom template, and for each post use a template part that contains code very similar to the 'content-single.php' file, generate_before_entry_title and other do_action's are not working, and therefore not showing post categories, date and Read more buttons.
What am I doing wrong? I've tried setting up postdata but that doesn't help.
Thanks
Hi,
Can you share us the code you're using?
generate_before_entry_title doesn't do anything by itself, it's a hook location.
The one in charge of generating meta is function is found in generatepress/inc/structure/.
The post-meta.php file. See generate_post_meta function.
https://github.com/tomusborne/generatepress/blob/master/inc/structure/post-meta.php
Here's the foreach -
<?php $latest_news = get_posts(array(
'post_type' => 'post',
'posts_per_page' => '3',
)); ?>
<section class="latest-news grid-container grid-parent">
<div class="latest-news-grid three-column-grid">
<?php foreach($latest_news as $post): setup_postdata($post); ?>
<?php get_template_part( 'news', 'card'); ?>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</section>
And this is what is in the news-card template part -
<article id="post-<?php the_ID(); ?>" <?php post_class('grey-border'); ?> <?php generate_do_microdata( 'article' ); ?>>
<div class="inside-article padding-20">
<header class="entry-header">
<?php do_action( 'generate_before_entry_title'); ?>
<?php $params = generate_get_the_title_parameters();
the_title( $params['before'], $params['after'] ); ?>
<?php do_action( 'generate_after_entry_title' ); ?>
</header>
<?php do_action( 'generate_after_entry_header' );
$itemprop = '';
if ( 'microdata' === generate_get_schema_type() ) {
$itemprop = ' itemprop="text"';
}
?>
<?php do_action( 'generate_after_entry_content' );
do_action( 'generate_after_content' ); ?>
</div>
</article>
The news card template part is working in the loop on index.php but doesn't show the post date, category, or read more on my custom homepage template.
Sorry I had the wrong news-card code but have updated the above post
Hi there,
Just to confirm, is this a custom post type where you've set up a custom file structure, and now things like post meta etc.. aren't being displayed?
If so, these filters may help:
https://docs.generatepress.com/article/generate_entry_meta_post_types/
https://docs.generatepress.com/article/generate-footer-meta-post-types/
Hi Tom,
This isn't a custom post type, just the standard WordPress posts. The entry and footer meta isn't appearing on the homepage when I use the template part.
Does this display anything?:
add_action( 'generate_before_entry_title', function() {
echo 'hello';
} );