WordPress Custom Post Type Getting List of Categories

go to my Profile Page, send your WP login to me, and I will fix your code.

PrimaThemes said

just an advice from me, please don’t write too many “not working” words here… :smiley:

we are trying to help you and we can not always give you the correct and perfect answer because we don’t see your full code.

we also provide some reference for you, for example read this page carefully…

you can get all what you need by reading that page…

SO, the most important thing, learn how to debug your PHP code please:wink:

for example, you can add additional code to print your $args value, for example

    $args=array(
      'headline' =>  $term->name,
      'post_type' => 'portfolio',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'ignore_sticky_posts'=> 1
    );
    print_r($args);

if you get ‘headline’ => empty, then it means there is a problem from the previous code, and it makes WP_Query will not return the right posts.

just my two cents.

I am very newBee developer so hope you understand.

PrimaThemes said

go to my Profile Page, send your WP login to me, and I will fix your code.

Thankx for your kind help, i am working on localhost can i past a whole complete code here. :smiley:

This Code Working :smiley: but for catgoires not for custom post type categories any suggestion for:

function getCategoryPostList($args = array())
{
    if (is_string($args)) {
        parse_str($args, $args);
    }
 
    // Set up defaults.
    $defaults = array(
        'echo'        => true,
    );
 
    // Merge the defaults with the parameters.
    $options = array_merge($defaults, (array)$args);
 
    $output = '';
 
    // Get top level categories
    $categories = get_categories(array('hierarchical' => 0));
    // Loop through the categories found.
    foreach ($categories as $cat) {
        // Print out category name
        $output .= '

' . $cat->name . '

'; // Get posts associated with the category $tmpPosts = get_posts('category=' . $cat->cat_ID); // Make sure some posts were found. if (count($tmpPosts) > 0) { $output .= '
'; // Loop through each post found. foreach ($tmpPosts as $post) { // Get post meta data. setup_postdata($post); // Print out post information $output .= '

' . $post->post_title . '

'; $output .= '

' . $post->post_excerpt . '

'; } $output .= '
'; } } if ($options['echo'] == true) { // Print out the $output variable. echo $output; } // Return return $output; }

i think changing will be that line:

$tmpPosts = get_posts('post_type=headline&category=' . $cat->cat_ID);

Thankx friends with all of your’s help i done my job with this code:

<?php 
$post_type = 'portfolio';
$tax = 'headline';
$tax_terms = get_terms($tax);
if ($tax_terms) {
  foreach ($tax_terms  as $tax_term) {
    $args=array(
      'post_type' => $post_type,
      "$tax" => $tax_term->slug,
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
  
    $my_query = null; 
    $my_query = new WP_Query($args); 
    if( $my_query->have_posts() ) { 
      echo '

'.$tax_term->name.'

'; while ($my_query->have_posts()) : $my_query->the_post(); ?>

<?php the_title(); ?>

<?php endwhile; } wp_reset_query(); } } ?>

:smiley: