Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm display a dropdown list of custom post types in wordpress. This first block of code uses WP_Query

$houseQuery = new WP_Query(
    array(
        'post_type' => 'house',
        'order'     => 'ASC',
        'post_status' => 'publish',
        'orderby'   => 'title',
        'nopaging' => true,
        'tax_query' => array(
        array(
            'taxonomy'  => 'teamtype',
            'field'     => 'slug',
            'terms'     => 'sectorteam', // exclude house posts in the sectorteam custom teamtype taxonomy
            'operator'  => 'NOT IN')
        ))
);
if( $houseQuery ->have_posts() ) :
    while ($houseQuery ->have_posts()) : $houseQuery->the_post();
        if(get_the_ID()==$c)
            $name=$post->post_title;
        echo '{ value:'.get_the_ID().', label: "'.get_the_title(get_the_ID()).'"},';
    endwhile;
endif;

This is the second cut of the code which uses 'wp_dropdown_page()' method and is a bit more concise

$args = array (
    'id' => 'house',
    'name' => 'house',
    'echo' => 1,
    'post_type' => 'house'
);
wp_dropdown_pages($args);

I need to exclude the posts defined by the 'tax_query' in the first example but am ensure how this can be done with the arguments that 'wp_dropdown_pages' uses.

I would like to only invoke one Query as part of the solution.

share|improve this question
    
You appear to be confusing $houseQuery and $companyList in your first code. –  vancoder Apr 10 '13 at 17:00
    
i corrected the sudo code. i failed to make clear that i only want to execute one query as part of the solution, since i realise i could build the list of excludes in a seperate query and then pass this to the wp_dropdown_pages() method. –  emeraldjava Apr 10 '13 at 17:39

1 Answer 1

up vote 1 down vote accepted

Amusingly, the codex for wp_dropdown_pages includes this:

It is possible, but not confirmed, some of the paramters for the function get_pages could be used for wp_dropdown_pages.

This must be at least partly true as I assume your use of post_type as an argument is successful. That being the case, give exclude a shot too.

In your companyList loop, build an array of post IDs to exclude:

$name=$post->post_title;
echo '{ value:'.get_the_ID().', label: "'.get_the_title(get_the_ID()).'"},';
$exclusions[] = get_the_ID();

Then just throw that argument into your wp_dropdown_pages:

$args = array (
    'id' => 'house',
    'name' => 'house',
    'echo' => 1,
    'post_type' => 'house',
    'exclude' => $exclusions
);
share|improve this answer
    
I made no mention of using tax_query - did you read my answer? –  vancoder Apr 10 '13 at 16:48
    
I did try the exclude but the documentation says this applies to a category and not a taxonomy –  emeraldjava Apr 10 '13 at 16:56
    
Am I missing something in your question? Do you not want to exclude the posts (found in your first sample) from wp_dropdown_pages (in your second sample)? –  vancoder Apr 10 '13 at 17:01
    
Yes - I want to exclude the posts found by the first sample when using the wp_dropdown_pages sample. –  emeraldjava Apr 10 '13 at 17:16
    
Then my answer should work. Please try it as I described. –  vancoder Apr 10 '13 at 17:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.