Home > Enterprise >  How to get item titles from custom post type in php?
How to get item titles from custom post type in php?

Time:11-13

so I have created custom post types in WordPress called podcasts with different packages and most of it has been completed now what I'm trying to do is to "get each available podcast / item title underneath the package" for example I've 3 packages called Basic, Starter and Exclusive and I want to display all items available in Basic package underneath the Basic Bundle and same for Starter and Exclusive. I have mentioned the code below currently it's showing all the item titles.

<div class="container-intro-head">
<div class="row">
                        
    <div class="col-md-4">
        <h3 class="package-head-intro">BASIC BUNDLE - $9.99</h3>
        <?php if($get_packages_list){?>
        
        <?php foreach($get_packages_list as $get_package){
            $podcasts = get_field('podcasts', $get_package->ID);
            $minimum_price = get_field('minimum_price', $get_package->ID);
            foreach($podcasts as $podcast){
            $podcast_details = get_post($podcast);
            ?>              
                                            
            <!--Display Items only available in Basic Bundle-->
            <h5 class="item-main-title"><?php echo $podcast_details->post_title; ?></h5>
                                            
            <?php 
            }
            }?>             
            <?php }?>
    </div>
                            
    <div class="col-md-4">
        <h3 class="package-head-intro">STARTER BUNDLE - $14.99</h3>
    </div>
                            
    <div class="col-md-4">
        <h3 class="package-head-intro">EXCLUSIVE BUNDLE - $19.99</h3>
    </div>
</div>

CodePudding user response:

I guess this is what you're looking for

<div class="container-intro-head">
<div class="row">
                        
    
        <?php if($get_packages_list){?>
        
        <?php foreach($get_packages_list as $get_package){
  $podcasts = get_field('podcasts', $get_package->ID);
            $minimum_price = get_field('minimum_price', $get_package->ID);
?>
<div class="col-md-4">
        <h3 class="package-head-intro"><?=get_the_title($get_package->ID);?></h3>
<?php
          
            foreach($podcasts as $podcast){
            $podcast_details = get_post($podcast);
            ?>              
                                            
            <!--Display Items only available in Basic Bundle-->
            <h5 class="item-main-title"><?php echo $podcast_details->post_title; ?></h5>
                                            
            <?php 
            }
?>
    </div>
<?php
            }?>             
            <?php }?>

                            
   
</div>

you get to solve the details i guess :)

  • Related