• michaelkturk

    (@michaelkturk)


    In the lower right corner of this page is a box labeled “Proclamations & Resolutions” that displays resolutions of support communities have passed.

    https://www.aviationacrossamerica.com/state-local-activity/state-activity-texas/

    The code that pulls that is:

    <?php
    $args = array(
    	'post_type' => array ('proclamation'),
      	'tag' => 'texas',
      	'posts_per_page' => 100,
      	'orderby' => 'date',
      	'order' => 'desc',
    );
     $procposts = new WP_query ($args);
     if ( $procposts->have_posts() ) : while ( $procposts->have_posts() ) : $procposts->the_post(); ?>
                    <option value="<? echo the_permalink(); ?>"><?php the_title(); ?></option>
     <?php endwhile; endif; ?>

    But for some reason WP_query is also pulling in posts from the post_type “tribe_events” that are tagged with Texas.

    I thought it was a problem with it pulling the events because they share the tag, but we have ten or so different custom post types that are also tagged Texas and not getting pulled in. It’s specific to the tribe_events post type.

    Any ideas why limiting the loop to proclamations isn’t filtering out the tribe_event type?

Viewing 6 replies - 1 through 6 (of 6 total)
  • kevmatic33

    (@kevmatic33)

    Without seeing all of your code it’s hard to say for sure, but you might need to either reset the query using wp_reset_query() or by using wp_reset_postdata()

    Rajesh Soni

    (@rajeshsoni)

    What do you get

    'post_type' => array ('proclamation', 'other_post_type_containing_texas_as_tag'),

    Also try this…

    'post_type' => 'proclamation',
    Thread Starter michaelkturk

    (@michaelkturk)

    Rajesh, I had it without the array and got the same issue, but added that since WordPress doesn’t have a ‘category__not_in’ equivalent for post types. My understanding is they get ignored unless specifically called (as they are here). But I tried the single value array just as an exercise in redundancy.

    Thread Starter michaelkturk

    (@michaelkturk)

    kevmatic33, the reset didn’t work. I can’t get the forum to load the full text of the code, so here is a link to it in text.

    https://www.aviationacrossamerica.com/pageCode.txt

    The loop starts at line 92.

    Thread Starter michaelkturk

    (@michaelkturk)

    Sorry, Rajesh, missed the first part of the question. If I tag ‘post’, for instance, I get hundreds of articles that mention Texas.

    Thread Starter michaelkturk

    (@michaelkturk)

    Well, I figured out a way around it, but still don’t know what’s causing it. The Event Calendar Pro plugin (which is what we’re using for the events) has its own taxonomy for tags and categories, and we have meta for all the events based on what kind of event they are. We can use the tax_query to exclude those so the code looks like this:

    <?php wp_reset_query();
    $args = array(
    	'post_type' => 'proclamation',
      	'tag' => 'texas',
    	'tax_query' => array (
    		array(
    			'taxonomy' => 'tribe_events_cat',
    			'field'    => 'term_id',
    			'terms'    => array( 92,93,94,97),
    			'operator' => 'NOT IN',
    		),
    	),
      	'posts_per_page' => 100,
      	'orderby' => 'date',
      	'order' => 'desc',
    );
     $procposts = new WP_query ($args);
     if ( $procposts->have_posts() ) : while ( $procposts->have_posts() ) : $procposts->the_post(); ?>
                    <option value="<? echo the_permalink(); ?>"><?php the_title(); ?></option>
     <?php endwhile; endif; ?>

    That strips out the events, but leaves the proclamations.

    I’ll leave this open in case anyone knows why the post_type argument is being ignored. Maybe this is happening with other users of Event Calendar Pro.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP_query Pulling wrong post type’ is closed to new replies.