1

I have one page lets call it page-home.php and I also have a page called page-custom-field.php I want to have a section of the first page where it loops through page-custom-field.php page and display it on itself. Here is my code attempting that so far. I am using advanced custom fields on the second page.

My If statements

page-home.php

 <?php
        $args = array(
            'post_type' => array(
                'features'
            ),
            'posts_per_page' => 1,

          );
        $query = new WP_Query( $args );
      ?>

    <div id="homeSpecials" class="section__content small-12 small-centered medium-10 columns">
    <?php  if($query -> have_posts()) : while( $query->have_posts() ) : $query->the_post(); ?>
              <?php include 'page-custom-field.php' ?>
      <?php endwhile; endif;//ends'menu_flexible'?>

page-custom-field.php

   <?php if( have_rows('menu_item') ): ?>
        <?php while( have_rows('menu_item') ): the_row(); ?>
            <!-- loop through the rows of data || DONT CLOSE THE LOOP IN AN 'IF' STATEMENT -->
            <?php if( get_row_layout() == 'simple_menu_item' ): ?>
                <article class="menu-item small-12 medium-6 columns">
                    <h3><?php the_sub_field('item_name') ?><span class="menu-item__price"><?php the_sub_field('item_price') ?></span></h3>
                    <p>
                        <?php the_sub_field('item_description') ?>
                    </p>
                </article>
            <!-- elseif is the last loop -->
            <?php elseif( get_row_layout() == 'line_item_with_modifiers' ):  ?>
                <article class="menu-item small-12 columns">
                <h3><?php the_sub_field('item_name') ?><span class="menu-item__price"><?php the_sub_field('item_price') ?></span></h3>
                <p>
                    <?php the_sub_field('item_description') ?>

                </p>
                <?php if( have_rows('item_modifiers') ): ?>
                    <?php while( have_rows('item_modifiers') ): the_row(); ?>
                        <div class="small-12 medium-3 columns">
                            <h4><?php the_sub_field('modifier_title') ?></h4>
                            <ul>
                                <?php if( have_rows('modifier_column') ): ?>
                                    <?php while( have_rows('modifier_column') ): the_row(); ?>
                                        <li><?php the_sub_field('modifier_name') ?></li>
                                    <?php endwhile;?>
                                <?php endif;?>
                            </ul>

                        </div>
                    <?php endwhile;?>
                <?php endif;?>


                </article>


            <!-- final 'endif' closes the flexible content loop -->
            <?php  endif; ?>
        <?php endwhile; endif;//ends'menu_flexible'?>
0

Figured it out just had to do this , the page-custom-field.php is included to shorten the code.

<?php  $query = new WP_Query( array( 'pagename' => 'features' ) ); ?>  
    <?php  while ( $query->have_posts() ) : $query->the_post(); ?>

        <?php include page-custom-field.php' ?>

    <?php endwhile; ?>

<?php  wp_reset_postdata(); ?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.