WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP_Query Taxonomy Parameters (3 posts)

  1. BRG Web
    Member
    Posted 5 months ago #

    I am trying to query a custom post type but it is not working.

    I am using Elegant Theme's Nexus with All in One Event Calendar.

    The theme has a featured slider in the home page that gets the recent posts from a regular post category and displays it as slides. I want it to get the recent events from AIO Event Calendar, that are saved as a specific post type and display as slides.

    The original code for the featured slider in the homepage is:

    <?php
    	$i = 1;
    
    	$featured_args = array(
    		'posts_per_page' => is_category() ? 2 : 4,
    		'cat'            => (int) get_catId( ( is_category() ? get_query_var( 'cat' ) : et_get_option( 'nexus_feat_posts_cat' ) ) ),
    	);
    
    	if ( is_category() ) {
    		$sticky_posts = get_option( 'sticky_posts' );
    
    		if ( is_array( $sticky_posts ) ) {
    			$featured_args['post__in'] = $sticky_posts;
    		} else {
    			$featured_args['orderby'] = 'rand';
    		}
    	}
    
    	$featured_query = new WP_Query( apply_filters( 'et_featured_post_args', $featured_args ) );
    ?>

    I changed the $featured_args like this:

    <?php
    	$i = 1;
    
    	$featured_args = array(
    		'posts_per_page' => is_category() ? 2 : 4,
    		/*'cat'            => (int) get_catId( ( is_category() ? get_query_var( 'cat' ) : et_get_option( 'nexus_feat_posts_cat' ) ) ),*/
    		'post_type' => 'AI1EC_POST_TYPE'
    	);
    
    	if ( is_category() ) {
    		$sticky_posts = get_option( 'sticky_posts' );
    
    		if ( is_array( $sticky_posts ) ) {
    			$featured_args['post__in'] = $sticky_posts;
    		} else {
    			$featured_args['orderby'] = 'rand';
    		}
    	}
    
    	$featured_query = new WP_Query($featured_args ) );
    ?>

    But nothing is showing in the slider anymore.

    What am I doing wrong?

    The nexus theme: http://www.elegantthemes.com/demo/?theme=Nexus
    All in One Event Calendar: http://wordpress.org/plugins/all-in-one-event-calendar/

    The site that I am trying to do this: http://brgweb.com.br/ibmundial

    Thanks!

  2. bcworkz
    Member
    Posted 5 months ago #

    AI1EC_POST_TYPE is not a string, it is a constant, so it does not belong in quotes. Use this: 'post_type' => AI1EC_POST_TYPE

  3. BRG Web
    Member
    Posted 4 months ago #

    Thank you @bcworkz. It worked perfectly!

Reply

You must log in to post.

About this Topic