Hot answers tagged custom-taxonomy
3
Given the standard registration, you should have the following:
A post type with the name 'recipe'
A recipe post archive at example.com/recipe/
Recipe posts with urls that take the form example.com/recipe/helloworldrecipe/
A template archive-recipe.php
A template single-recipe.php
However, I see this in your registration code:
'rewrite' => ...
2
That field can return multiple term objects depending on how you've got it configured, so I'll guess that $series in this case is an array containing a single element, which contains your term object. Try inspecting the contents of series:
print_r( $series );
You'll probably see something like:
Array
(
[0] => stdClass Object
(
...
2
When you initiate a Loop, split it up like so:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
<?php endwhile; ?>
<?php endif; ?>
Anything inside the if statement but outside the while statement will run if have_posts is true, but will not be ...
1
Since wp_set_post_terms() does not accept hierarchy for it, you will first have to check if terms exist already, create them using wp_insert_term() if not and only then assign to post.
Note that there had been (don't know current state) some cache related bugs with doing such things on the fly, see Inserting terms in an Hierarchical Taxonomy
1
From what I gather all you need to do is query the 3 posts and step though each one using the_post(). I have not used it like this so not 100% that is how it works.
the_post() Retrieves the next post, sets up the post, sets the 'in the loop' property to true.
$project_query = array(
'posts_per_page' => 3,
'post_type' => 'projects',
...
1
It's because within wp_insert_post current user capabilities are checked before adding the terms:
if ( current_user_can($taxonomy_obj->cap->assign_terms) )
wp_set_post_terms( $post_ID, $tags, $taxonomy );
to get around this, use wp_set_object_terms instead after wp_insert_post to add the terms:
$new_post = array(
'post_title' => ...
1
The problem can only be one of the following:
Your taxonomy "recipecategory" does not exist.
Your taxonomy has no terms.
None of your recipecategory terms have any posts. In this case, make the following change:
$tax_terms = get_terms($taxonomy, array('hide_empty' => false));
This should work as it will override the default setting, which is to ...
Only top voted, non community-wiki answers of a minimum length are eligible
