Search
 
SCRIPT & CODE EXAMPLE
 

PHP

post type taxonomy loop wordpress

<?php
// Get all the categories
$categories = get_terms( 'service-category' );

// Loop through all the returned terms
foreach ( $categories as $category ):

    // set up a new query for each category, pulling in related posts.
    $services = new WP_Query(
        array(
            'post_type' => 'services',
            'showposts' => -1,
            'tax_query' => array(
                array(
                    'taxonomy'  => 'service-category',
                    'terms'     => array( $category->slug ),
                    'field'     => 'slug'
                )
            )
        )
    );
?>

<h3><?php echo $category->name; ?></h3>
<ul>
<?php while ($services->have_posts()) : $services->the_post(); ?>
    <li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>

<?php
    // Reset things, for good measure
    $services = null;
    wp_reset_postdata();

// end the loop
endforeach;
?>
Comment

PREVIOUS NEXT
Code Example
Php :: combine date and time in php 
Php :: undefined method JeroenNotenLaravelAdminLteHelpersMenuItemHelper::isSearchBar() 
Php :: php check if date is older than 1 month 
Php :: random string php 
Php :: loop object property laravel 
Php :: how to loop array in laravel 
Php :: php date modify plus 1 day 
Php :: how login with phone in laravel 
Php :: laravel Filesystem chmod(): Operation not permitted 
Php :: count number of rows laravel controller 
Php :: laravel blade check if yielded content exists 
Php :: php date format iso 
Php :: how to check if there is an authenticated user laravel 
Php :: message mkdir() invalid path filename drivers/session_files_driver.php 
Php :: php pi() function 
Php :: php multidimensional array get all values by key 
Php :: php get all php files in a directory 
Php :: php get start of today 
Php :: send mail test from laravel 
Php :: get post url from post id wordpress 
Php :: magento 2 print php error 
Php :: wordpress query multiple post ids 
Php :: e_notice in php 
Php :: check value falls between in two range in php 
Php :: laravel validation required_if one parameter exist 
Php :: laravel tinker generate password 
Php :: how to check mobile or desktop in php 
Php :: convert image to base64 in laravel 
Php :: target class usercontroller does not exist. in laravel 8 
Php :: add log in laravel 8 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =