WordPress.org

Forums

custom taxonomy WP_Query() with custom post type comes up empty (5 posts)

  1. chrisruggia
    Member
    Posted 3 years ago #

    Hello,

    I have been struggling for several days with filtering a custom post type ("testimonial") by a custom taxonomy ("quote-page").

    My post type query works fine until I add the taxonomy, at which point it returns no posts.

    I have tried renaming the taxonomy several different ways, looking for conflicts

    Here's the taxonomy registration code:

    function quotepage_init() {
    
    register_taxonomy(
    		'quote-page',
    		'testimonial',
    		array(
    			'label' => __('Quote Page'),
    			'sort' => true,
    			'args' => array('orderby' => 'term_order'),
    			'query_var' => true,
    			'hierarchical' => true,
    			'rewrite' => array('slug' => 'quote-page')
    		)
    	);
    }
    add_action( 'init', 'quotepage_init' );

    The post type registration:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    And the Query :

    <?php $args = array(
    			'post_type' => 'testimonial',
    			'quote-page' => 'river-trips',
    			'orderby' => 'rand',
    			'showposts' => '-1',
    			);
    		$testimonials = new WP_Query($args);

    There is one testimonial with "river-trips" as its quote-page value, which I have verified using echo the_terms( $post->ID, 'quote-page');

    I have tried most of the variations suggested in this thread to no effect:
    http://wordpress.org/support/topic/custom-taxonomy-and-query_posts?replies=23

    Can anyone see what I'm doing wrong? Thanks in advance for any help.

  2. chrisruggia
    Member
    Posted 3 years ago #

    Please ignore this second post - clumsiness with the forum software...

  3. chrisruggia
    Member
    Posted 3 years ago #

    I just realized that when I said "please ignore", one might have thought I meant the entire topic, and not just the extra post.

    I do really need some help, if anyone can offer it. Thanks very much for any suggestions.

  4. chrisruggia
    Member
    Posted 3 years ago #

    Update:

    The code works when I use a taxonomy terms without hyphens in it.

    'river-trips' does not work, but 'directions' does.

    Does anyone know of a problem with punctuation within a taxonomy?

  5. chrisruggia
    Member
    Posted 3 years ago #

    Final Update:

    Turns out it was not a punctuation problem, but a slug problem.

    When I viewed the dashboard page for my taxonomy, I found that 'river-trips' apparently had been created, deleted, and created again, because its slug was not 'river-trips' but 'river-trips-2', causing my code not to work.

    Now I'm headed to manually edit the database to try to get rid of any trace of the original slug so my code can work...

    But the problem above can be considered resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic