• ttmt

    (@ttmt)


    Hi all

    I’m developing a theme for a cafe.

    The page structure is something similar to

    Home
            |
            Menu
                |
                Starters - starter_1 - starter_2
                |
                Mains - main_1 - main_2
                |
                Desserts - dessert_1 - dessert_2

    Starters, Mains and Desserts are child pages of Menu. Menu is just a structural page, Menu goes straight to Starters.

    starter_1, main_1 etc are posts with titles, descriptions and prices (custom field). These post have tags that are the same as the title of the page they are on. So starter_1 and starter_2 have ‘starter’ as a tag.

    On the pages Starters, Mains and Desserts I’m adding posts that have tags the same as this page loading.

    <?php
    
            	$pagetitle = get_the_title('');
    
            	$pageTag = strtolower($pagetitle);
    
            	$args = array(
            		'tag' => $pageTag,
            		'order' => 'ASC'
            	);
    
            	$course = new WP_Query($args);
    
            	if($course->have_posts()):
            		while($course->have_posts()):
            			$course->the_post();
    
            ?>
    
            <div >
            	<h3><?php echo get_the_title(); ?></h3>
            	<?php the_content(); ?>
            	<em><?php echo get_post_meta($post->ID, 'price', true); ?></em>
            </div>
    
            <?php	
    
            	endwhile;
    
            	endif;
    
            	wp_reset_postdata();
    
            ?>

    Now I want a page that shows all meals and prices – a price list.

    I wanted to loop through the children of Menu and then get the posts that match that page title to give me the posts for that page.
    Then just pull out the title and price.

    The page structure would be something like.

    <h3>Starters</h3>
    
    <ul>
    <li>Starter_1<span>Price</span></li>
    <li>Starter_2<span>Price</span></li>
    </ul>
            <h3>Mains</h3>
    
    <ul>
    <li>Main_1<span>Price</span></li>
    <li>Main_2<span>Price</span></li>
    </ul>
            …

    I’m a bit stuck on how to start this.

    Do I loop through the children of Menu then loop again to get the posts. If so how.

    Any help, pointers much appreciated.

  • The topic ‘Price list, query/loop within query/loop.’ is closed to new replies.