WP Loop action not writing php in wp-loop-empty items

Edit: This appears to be beyond just partials. It seems to be an issue with any WordPress actions or anything that writes PHP.

Original Message:
The Reusable Template Part smart action and the get_template_part() action don’t create the correct PHP when used in the “show element if empty” part of a loop. It doesn’t matter if I’m using the Show Posts smart action or the regular loop actions; the behavior is the same.

Here is a screenshot of the tree and WP actions.

Here is the generated code.

<div class="layout__contained layout__x-padding main__innerwrapper">
    <div class="layout__single-container">
        <main id="content">
                <?php get_template_part( 'template', 'parts/partials/title' ); ?>
            <?php if ( have_posts() ) : ?>
                <section role="region" aria-label="Articles">
                    <div class="article-card__wrapper">
                            <?php while ( have_posts() ) : the_post(); ?>
                                <?php PG_Helper_v2::rememberShownPost(); ?>
                                <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                                    <?php get_template_part( 'template', 'parts/partials/articlecard' ); ?>
                            <?php endwhile; ?>
                    <?php get_template_part( 'template', 'parts/partials/pagination' ); ?>
            <?php else : ?>
                <div cms-template-part="template-parts/content/content-none" data-pg-name="No Content" wp-loop-empty></div>
            <?php endif; ?>

Interestingly, the code preview window shows the correct PHP code, which works fine when I manually put it directly into the partial file.

Unfortunately, I can’t even use a PHP code block since it doesn’t get written properly inside that area.

Generates the code:

Moving the PHP block out of the section works correctly but doesn’t give me the ability to insert the partial inside the else statement.

(Also, there is an issue with the way the reusable template part smart action handles dashes. I’ll write s separate bug report for that one)

@adamslowe I’m looking at changing this. As a workaround you can use

<?php get_template_part(...) ?>

directly in the source HTML code, instead of

1 Like