SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    calling in multiple categories.

    Code:
    $new_query = new WP_Query('category_name=news','category_name=cta' )
    Doesn't seem to work
    searched the codex but so far have not seen an answer.
    Has anyone here run into this? how can i call multiple categories please?
    thank you
    D

  2. #2
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, why don't use this Content Views plugin http://wordpress.org/plugins/content...lay-post-page/

    It is easy to query post(s) by multiple categories, without coding!

    It even offers you more awesome features

    Hope this helps

  3. #3
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hello Place. Yes you are right it probablly would be easier to use plugins (& i have for contact forms) but I think it is always better to be able to understand how to create things yourself as much as possible.
    A bit like the difference between being able to create a piece of art or a remarkable dinner versus buying one or buying a frozen entree. ((which i have also have done... :-) take out is better really)

  4. #4
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    As in your first post, you want to query 2 categories: news, cta.
    So this is the query for you (if you want to code yourself):

    Code:
    $args = array(
    	'post_type' => 'post',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'field' => 'slug',
    			'terms' => array( 'news', 'cta' )
    		),
    	)
    );
    $query = new WP_Query( $args );

  5. #5
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    795
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That is an interesting solution Theme, might try it out but was thinking there should have been a more direct way. this is what i currently have
    This simple line uses the post/page number to for href. so far so good
    PHP Code:
    <p><ahref="index.php?p=13" target="_blank" class="btn btn-primary special">tech</a></p
    And this is what i use to call one category. I think i just tried doubling that parameter and it didn't work.
    PHP Code:
                <?php
                    $new_query 
    = new WP_Query('category_name=tech' );
                        while ( 
    $new_query->have_posts() ) : $new_query->the_post();
                            echo 
    get_the_post_thumbnail();    
                        
    ?>
    <h5><a href="<?php the_permalink(); ?>" class="btn btn-primary special"><?php the_title(); ?></a></h5>
            
                        <?php endwhile; ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •