Wordpress Archive Page for a custom taxonomy element - wordpress

I have a custom post type clientgallery and the custom taxonomy client.
To get all galleries I can type website.com/clientgallery.
But I want to show only galleries of a specific client, like: website.com/clientgallery/miller
So, miller should act like a get parameter.
I already know how to get the galleries by client, but I don't know how to get the parameter part working.
$args = array(
'numberposts' => -1, //limit the number of posts, set 0 if no limit required.
'orderby' => 'post_date', //order by post_date field.
'order' => 'DESC', //order by descending oder.
'post_type' => 'clientgallery', //the post type is custom post type 'News & Events'
'post_status' => 'publish', //post status is 'publish'
'tax_query' => array(
array(
'taxonomy' => 'client', //custom taxonomy slug
'field' => 'slug', //select taxonomy term by slug
'terms' => $_GET['client'] //taxonomy term is called 'home-page'
)
));

Call it taxonomy-client.php :
See all info here on template hierarchy for WordPress : http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

If your taxonomy client is only associated with the clientgallery post type, then website.com/client/miller should suffice to show your list of clientgalleries for this client. I tested it on my site, it works. Or am I getting something wrong?

Related

wp_insert_posts for cpt with category or wp_set_post_categories

I have an import-script for custom post-type contents. I need to add some categories to the posts. But after insert the categories are not added to the post (custom post type 'memember_pages')
My insert-statements:
$insertargs = array(
'post_author' => $user_id,
'post_content' => $page->beschreibung,
'post_title' => $page->name,
'post_status' => 'publish',
'post_category' => array(7,14),
'post_type' => 'member_pages'
);
$insertresult = wp_insert_post($insertargs,true);
$insertresult returns the new post->ID, no errormessage.
The category-ID's exists of course.
The insert works, but without the categories.
The values 7,14 are only examples, which shows that I use (existing) ID's
I tried wp_set_post_categories too, but it also does not work.
wp_set_post_categories returns array(0) when using it.
Any idea to add categories to cpt?
thanks,
rudi

Wordpress, How to filter by taxonomy from custom post type

I created Custom post type named "Syllabi Archive" and added custom taxonomy Named " Program, Academic Year and Semester " and now I want filter post by Taxonomy, Like shown in the image
enter image description here
I think you need something like this:
query_posts( array(
'post_type' => 'Syllabi Archive', // name without spaces
'posts_per_page' => -1, // show to all posts
'tax_query' => array(
array(
'taxonomy' => 'Program, Academic Year and Semester', //or tag or custom taxonomy without spaces
'field' => 'id',
)
)
) );

Advanced Custom Fields display specific category wordpress

I'm coding a wordpress website, but i've run into some problems.
I have through Advanced Custom Fields make a new post type with a category.
I want to display a specific category in my wordpress loop, but for some reason it will not work.
<?php
$args=array(
'post_type' => 'medlem',
'cat' => 4,
);
$medlem = new WP_Query($args);
<?php if ( $medlem->have_posts() ) : while ( $medlem->have_posts() ) : $medlem->the_post(); ?>
It just display all categories, which is not the meaning. Some help?
Are you sure that your Custom Post Type have registered to "category" taxonomy type?
What do you mean by 'I have through Advanced Custom Fields make a new post type with a category.', because ACF is for creating custom fields to existing post types.
I think you could try this code:
$args = array(
'post_type' => 'medlem',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => 4
)
)
);
As 'field' => 'term_id' is default you can skip this line.
For more information go to: http://codex.wordpress.org/Class_Reference/WP_Query

Advanced custom fields filtering with taxonomies

I'm working with AdvancedCustomFields and Taxonomies, and I don't find, in the documentation, something that allows me to filter the Taxonomies by the values stored on the wp_options table.
I found that here.
And, it could by something like this, but with Taxonomies:
I have a taxonomy called "Person", and I have many fields. For example, I would like to filter by sex and country.
Is there any function that allows me to do this? Or should I work with WP-Query?
Thanks in advance
Once you have registered the taxonomy with your post you may try with tax_query Query inside the your query_post
query_posts( array(
'post_type' => 'your post type',
'paged' => $paged,
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'person', //or tag or custom taxonomy
'field' => 'id'
)
)
) );

Query posts by custom taxonomy ID

I have a custom post type called portfolio and a custom taxonomy called build-type (acting as categories)
I am trying to query portfolio posts by build-type ID e.g. all Portfolio posts in "Hotels" (id=4 for that taxonomy)
// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array(
'post_type' => 'portfolio',
'showposts' => -1,
'tax_query' => array(
'taxonomy' => 'build-type',
'terms' => $buildType,
'field' => 'term_id'
),
'orderby' => 'title',
'order' => 'ASC'
));
Currently it's calling all portfolio posts and not just those with the build-type ID
For 'field' => 'term_id' should I be using term_id, tag_ID, id or something else?
Anyone know how to get this working?
Thanks in advance!
I solved it with help from: https://wordpress.stackexchange.com/questions/30476/query-posts-by-custom-taxonomy-id
tax-query needs to be an array of arrays
The final solution is:
// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array(
'post_type' => 'portfolio',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'build-type',
'terms' => $buildType,
'field' => 'term_id',
)
),
'orderby' => 'title',
'order' => 'ASC' )
);
On github here:
https://gist.github.com/1275191
I'm not a WP-gury and I have invested hours and hours trying to solve the same problem. Eventually I found this blog post: http://richardsweeney.com/blog/wordpress-3-0-custom-queries-post-types-and-taxonomies/
The answer is somewhat semi-bad: apparently you can't filter like this for custom post types (it is only possible for posts), which is a shame!
What I did work was this:
$args['custom_tax'] = 'custom_tax_slug';
query_posts($args);
Hope it helps!
//Mike

Resources