$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>loop - How do I go about looping through a advanced custom field on a particular page inside of another page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

loop - How do I go about looping through a advanced custom field on a particular page inside of another page

matteradmin9PV0评论

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'?>

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'?>
Share Improve this question asked Jan 8, 2019 at 22:11 Anders KitsonAnders Kitson 1571 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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(); ?>
Post a comment

comment list (0)

  1. No comments so far