• Hello.

    Below I am iterating through a custom-taxonomy to display each custom-post-type within the custom-taxonomy. This worked when I was using categories and posts instead of a custom-taxonomy and custom-post-type. Now it does not work.

    Here is the code:

    $catArgs = array( 'taxonomy' => 'sermon-series');
    $categories = get_categories($catArgs);
    foreach($categories as $category) {
    
    	$catPostArgs = array( 'category' => $category->term_id );
    	$catPosts = get_posts( $catPostArgs );

    And here is the dump. As you can see, I get an empty array from $catPosts even though my custom-taxonomy is returned fine.

    array(2) {
      [0]=>
      object(stdClass)#348 (15) {
        ["term_id"]=>
        &string(2) "23"
        ["name"]=>
        &string(31) "24 Hours that Changed the World"
        ["slug"]=>
        &string(31) "24-hours-that-changed-the-world"
        ["term_group"]=>
        string(1) "0"
        ["term_taxonomy_id"]=>
        string(2) "23"
        ["taxonomy"]=>
        string(13) "sermon-series"
        ["description"]=>
        &string(0) ""
        ["parent"]=>
        &string(1) "0"
        ["count"]=>
        &string(1) "1"
        ["cat_ID"]=>
        &string(2) "23"
        ["category_count"]=>
        &string(1) "1"
        ["category_description"]=>
        &string(0) ""
        ["cat_name"]=>
        &string(31) "24 Hours that Changed the World"
        ["category_nicename"]=>
        &string(31) "24-hours-that-changed-the-world"
        ["category_parent"]=>
        &string(1) "0"
      }
    [1]=>
      object(stdClass)#639 (15) {
        ["term_id"]=>
        &string(2) "22"
        ["name"]=>
        &string(19) "Sermon on the Mount"
        ["slug"]=>
        &string(19) "sermon-on-the-mount"
        ["term_group"]=>
        string(1) "0"
        ["term_taxonomy_id"]=>
        string(2) "22"
        ["taxonomy"]=>
        string(13) "sermon-series"
        ["description"]=>
        &string(0) ""
        ["parent"]=>
        &string(1) "0"
        ["count"]=>
        &string(1) "1"
        ["cat_ID"]=>
        &string(2) "22"
        ["category_count"]=>
        &string(1) "1"
        ["category_description"]=>
        &string(0) ""
        ["cat_name"]=>
        &string(19) "Sermon on the Mount"
        ["category_nicename"]=>
        &string(19) "sermon-on-the-mount"
        ["category_parent"]=>
        &string(1) "0"
      }
    }
    array(1) {
      ["category"]=>
      string(2) "23"
    }
    array(0) {
    }
    array(1) {
      ["category"]=>
      string(2) "22"
    }
    array(0) {
    }

The topic ‘get_posts() returns empty array’ is closed to new replies.