-1

I am trying to display a custom post type that has custom taxonomy, but I am not having any luck. Nothing is showing up. I appreciate any help.

Post type = banner

Custom Taxonomy = country

The 'country' I want to display = Algeria

My code :-

<?php
$slide = new wp_query( array ( 'post_type' => 'banner' , 'taxonomy' => 'country', 'term' => 'algeria', 
                            'meta_query' => array( 'relation' => 'AND',
                                                                        array('key' => 'page_ads','value' => 'home'),
                                                                        array('key' => 'position_ads','value' => 'top'))
                            ));

if ( $slide->have_posts() ) : while ( $slide->have_posts() ) : $slide->the_post(); 
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
?>   
<div class="item"><a href="<?php echo get_option("siteurl")?>/order-ads">    
<img src="<?php echo $image[0]; ?>" width="1350" height="515">   
                                </a>
                                </div> 
<?php
                            endwhile; endif;
                            wp_reset_query();
                            echo "</div><br>";
     }
                            ?>

Register taxonomy

// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_banner_taxonomies', 0 );

// create two taxonomies, genres and writers for the post type "book"
function create_banner_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name'              => _x( 'Country', 'taxonomy general name' ),
        'singular_name'     => _x( 'Country', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Country' ),
        'all_items'         => __( 'All Country' ),
        'parent_item'       => __( 'Parent Country' ),
        'parent_item_colon' => __( 'Parent Country:' ),
        'edit_item'         => __( 'Edit Country' ),
        'update_item'       => __( 'Update Country' ),
        'add_new_item'      => __( 'Add New Country' ),
        'new_item_name'     => __( 'New Country Name' ),
        'menu_name'         => __( 'Country' ),
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'country' ),
    );

    register_taxonomy( 'country', array( 'banner' ), $args );
}
-1

i think you posted the different code earlier. But if this is the code you are using right now then you should so this

$slide = new wp_query( array ( 'post_type' => 'banner' ,
                                'tax_query' =>
                                          array(
                                            array(
                                              'taxonomy' => 'country', 
                                              'field'    => 'name',
                                              'terms'    => 'algeria'
                                            ),
                                          ),                               
                               'meta_query' => array( 
                                                    'relation' => 'AND',                                                                        
                                                    array('key' => 'page_ads','value' => 'home'),
                                                     array('key' => 'position_ads','value' => 'top')
                                                     )
                            ));
  • i replace to WP_Query but not return any post – Zamalek Man Jul 6 '15 at 12:03
  • can you paste the whole code above and you sure you have registered the your custom post correctly... – terminator Jul 6 '15 at 12:25
  • i save correct in wp-admin but i don't knew why not get any post under taxonomy called algeria – Zamalek Man Jul 6 '15 at 12:30
  • may be could also post tto register custom post too – terminator Jul 6 '15 at 12:36
  • Currently you are able to save posts under taxonomy algeria right..? – terminator Jul 6 '15 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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