Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think you might be over complicating things. The following code would retrieve all the posts that have a value assigned in the ‘children’ taxonomy. You can add additional arguments to the query (orderby, order) to customize the results. (I believe by default it should return the posts in reverse chronological order.)

    $args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'children',
    			'field' => 'slug',
    			'terms' => get_terms('children','fields=names')
    		)
    	)
    );
    
    $my_query = new WP_Query( $args );

    This is one of those solutions where you have to read between the lines in the Codex (and do a bunch of searching for similar solutions).

    Your second chunk of code is on track. What you need to do is to specifically exclude all the descendant values. Here is an extension of your example that should work:

    $args = array(
      'taxonomy'     => 'document-category',
      'orderby' => 'name',
      'order' => 'DESC'
    );
    $categories = get_categories($args);  // An array populated with the taxonomy values of 'document-category' taxononmy
    
    echo '<ul>';   // Part of testing code to display values returned by query
    
    // Loop through all the taxonomy values
    foreach ($categories as $category) {
    
      // We need to get the list of all the taxonomy value's descendants to exclude
      $termchildren = get_term_children($category->term_id, 'geography');
    
      // We want only the posts for a given taxonomy value (and exclude its children)
      $wpq = array(
             'post_type' => 'document-tutorial',
               'orderby'  => 'title',
               'order'=>ASC,
               'posts_per_page'=>-1,
               'tax_query'=>
                array('relation' => 'AND',
                  array( 'taxonomy' => 'document-category',
    			'field' => 'slug',
    			'terms' => $category->name,
    			'operator' => 'IN'
    			),
                  array( 'taxonomy' => 'document-category',
    			'field' => 'id',
    			'terms' => $termchildren,
    			'operator' => 'NOT IN'
    			)
    	      )
               );
    
      // Query to get the posts
      $parentposts = new WP_Query($wpq);
    
      // Testing Code to display the results so we can see if everything is working correctly -- replace this with your "real" loop code.
      echo '<li>The taxonomy value is: ' . $category->name ;
      echo '<ul>';
    
      while ( $parentposts->have_posts() ) : $parentposts->the_post();
        echo '<li>The post title is: ' . get_the_title() . '</li>';
      endwhile;
      echo '</ul>';
    
      echo '</li>';
    
    } // end foreach
    
    echo '</ul>';     // Part of testing code to display values returned by query

    I tested this and it works. If you have trouble post a reply with your code and the problem you are running into. I’ll try and lend a hand.

    Good luck.

    I had this same issue and traced it to a problem in functions.php.

    I was using Starkers 3.0 as the basis for the theme and also the functions.php file included with it.

    If you look in functions.php you will find a “twentyten_filter_wp_title” function. It appears that this functions file was based on one supplied with TwentyTen at some point (although the current 3.0.4 TwentyTen functions.php does not include this function).

    To cut to the chase, this function adds a filter to wp_title and, in doing so, appends the site name to the end of the title – among other possible actions.

    I simply commented out the “add_filter( ‘wp_title’…)” line and that fixed the issue. I’m not sure if I broke anything else, so use this at your own risk.

    I hope this helps the next person who spends a chunk of their life tracking down the source of this problem.

    After receiving this same error and spending a bunch of time tracing it I discovered that it was somehow related to a “hiccup” in the FTP upload process. I put an “echo” statement in the query.php file located in the wp-includes subdirectory (this is where the is_admin() function is defined).

    As soon as I uploaded the edited file everything worked (well not really because I had to remove the ECHO statement first).

    My suggestion is to re-upload the query.php file and try again.

    After tracing all the code prior to the error I can attest that the code is solid. The problem was definitely due to the uploaded file not being quite 100%. Why that didn’t throw an error when it got called is beyond me.

    Hope this saves time for the next shlep like me who comes along with this issue.

Viewing 4 replies - 1 through 4 (of 4 total)