Community Forums › Forums › Archived Forums › General Discussion › Custom Taxonomy Archive
- This topic has 7 replies, 3 voices, and was last updated 9 years, 5 months ago by
mmjaeger.
-
AuthorPosts
-
August 9, 2014 at 9:17 pm #118014
mmjaeger
MemberHello
I've a custom page and I like to show all pictures on that page with a certain tag - the taxonomies are called keys .I've put the following code into the template file:`add_action( 'pre_get_posts', 'nv_pre_get_posts' );
function nv_pre_get_posts( $query ) {$query->set( 'post_type', 'attachment' );
$query->set( 'post_status', 'publish' );
$query->set( 'post_parent', null );
$query->set( 'mime_type', 'image' );
$query->set( 'orderby', 'date' );
$query->set( 'order', 'DESC' );$tax_query =
array(array(
'taxonomy' => 'keys',
'field' => 'slug',
'terms' => get_query_var( 'key' )));
$query->set( 'tax_query', $tax_query );
return $query;
}
`however, I only getting: Sorry, no content matched your criteria.
what am I missing
I also tried a custom loop but I could NOT get the pagination to work - always got a 404 - the first page worked just fine.
are there any examples out there how to set up a page that would show me all the attachment with a certain tag?
Thanks
August 9, 2014 at 10:05 pm #118020Summer
MemberHave you tried using the taxonomy template as defined by the WordPress template Hierarchy?
Also, is what you defined "key" or "keys"? That would make a difference... and now I'm also wondering if that would cause a namespace clash or not...
Depending on which name your term is, you'd create a template file (say taxonomy-keys.php), and in it you'd have something like this:
remove_action('genesis_loop', 'genesis_do_loop'); add_action('genesis_loop', 'child_main_loop'); function child_main_loop() { global $paged; $term = get_queried_object(); $args = array('post_type' => 'attachment', 'taxonomy' => $term->taxonomy, 'term' => $term->slug, 'order' => 'asc', 'paged' => $paged); genesis_custom_loop( $args ); }
followed by the genesis(); call to finish things off nicely... that's the general gist of it. You could add an "orderby" in there to get whichever sort you want.
WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
Slice of SciFi | Writers, After DarkAugust 10, 2014 at 7:11 am #118045mmjaeger
MemberThank you for replying - seem to work for the first page - however the pagination does not work - it shows up at the bottom of the page but click on e.g. page 2 leads to a 404 - any idea how to fix this?
thanks again.
August 10, 2014 at 9:37 am #118068mmjaeger
MemberI got one issue when putting the following code onto my page:
add_action( 'pre_get_posts', 'nv_pre_get_posts' ); function nv_pre_get_posts( $query ) { global $paged; $term = get_queried_object(); $query->set( 'post_type', 'attachment' ); $query->set( 'post_status', 'all' ); $query->set( 'posts_per_page', 16 ); $query->set( 'orderby', 'date' ); $query->set( 'order', 'DESC' ); $query->set( 'taxonomy', $term->taxonomy ); $query->set( 'term', $term->slug ); $query->set( 'paged', $paged ); return $query; }
for some reasons, the main navigation disappears - any idea why?
Thanks
August 10, 2014 at 1:12 pm #118084Summer
MemberI'm using that same code on a site and pagination works just fine. What other code do you have in your template?
I'm also not sure what you're saying... are you using the pre_get_posts function and the child loop function together?
WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
Slice of SciFi | Writers, After DarkAugust 31, 2015 at 2:21 pm #164160julyan
ParticipantSummer, thanks for your code. I used the child loop function as it is, but page 2 of the archive returns a 404. Same problem as mmjaeger.
August 31, 2015 at 2:24 pm #164162julyan
Participant//* adds custom loop for the specific taxonomy remove_action('genesis_loop', 'genesis_do_loop'); add_action('genesis_loop', 'child_main_loop'); function child_main_loop() { global $paged; $term = get_queried_object(); $args = array('post_type' => 'resources', 'taxonomy' => $term->taxonomy, 'term' => $term->slug, 'order' => 'asc', 'paged' => $paged); genesis_custom_loop( $args ); } //* The blog page loop logic is located in lib/structure/loops.php genesis();
Page 1 works great, but succeeding pages are 404s.
August 31, 2015 at 3:56 pm #164170mmjaeger
Memberthe following coded fixed it for me:
/** * Pagination: fix pagination issue with custom taxonomy archive page */ add_action( 'parse_query', 'mm_parse_query' ); function mm_parse_query() { if ( ! is_tax( 'media_tag' ) ) return; global $wp_query; $wp_query->query_vars[ 'post_type' ] = array( 'resources' ); $wp_query->query_vars[ 'post_status' ] = array( 'all' ); $wp_query->query_vars[ 'posts_per_page' ] = 16; }
you need to adjust the code to your settings e.g. the taxonomy name
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.