[Support request] generate_before_entry_title not working in WP Query loop

Home Forums Support [Support request] generate_before_entry_title not working in WP Query loop

Home Forums Support generate_before_entry_title not working in WP Query loop

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1624310
    Germaine

    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

    #1624320
    Elvin
    Staff
    Customer Support

    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

    A wise man once said:
    "Have you cleared your cache?"

    #1624379
    Germaine

    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.

    #1624395
    Germaine

    Sorry I had the wrong news-card code but have updated the above post

    #1625260
    Tom
    Lead Developer
    Lead Developer

    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/

    #1633707
    Germaine

    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.

    #1634560
    Tom
    Lead Developer
    Lead Developer

    Does this display anything?:

    add_action( 'generate_before_entry_title', function() {
        echo 'hello';
    } );
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.