can these be combined in a query?
-
My goal is to grab a list of posts in a custom post type that are also child of category 4, then have a link that goes to a category page — the category has the same name as the title being pulled.
This code works great for the first part, getting the list of posts:
<?php $args=array('category_name' => 'mycategoryname' , 'post_type' => 'mycustomposttypename',); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <h1><?php the_title(); ?></h1> <?php endwhile; } wp_reset_query(); ?>
Now, if I could refine the query further, I’m trying to find the permalink to a category with a name identical to what is shown in the_title. I thought this might help:
<?php $pageslug = $post->post_name; // name of the page (slug) $catslug = get_category_by_slug($pageslug); // get category of the same slug $catid = $catslug->term_id; // get id of this category $query= 'cat=' . $catid. ''; query_posts($query); // run the query ?>
But combining these two seems to be beyond me as I keep breaking everything.
If this is the wrong approach feel free to suggest alternatives.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘can these be combined in a query?’ is closed to new replies.