Making a form for user to add new custom post with custom taxonomies and custom fields

To list the options for a custom taxonomy you need to query the taxonomy terms. To do that you use get_terms() http://codex.wordpress.org/Function_Reference/get_terms // We are assuming color is the name of the taxonomy $colors = get_terms( ‘color’, array( ‘orderby’ => ‘name’, ‘hide_empty’ => 0 )); // Now loop through the colors and spit out the … Read more

Post to inherit custom category background image from parent

You can use this function to output the parent category ID and then style off of that. <?php function wpse_74737_category_top_parent_id($catid) { while ($catid) { $cat = get_category($catid); $catid = $cat -> category_parent; $catParent = $cat -> cat_ID; } return $catParent; } And then call this in your body class: <?php echo wpse_74737_category_top_parent_id( $cat->term_id ); ?>

Get 1st parent category id from post

You need to use get_ancestors(). Assuming your post is only in one category, the following code should work (if it’s in multiple you’ll need to loop through each of the assigned categories to determine the various hierarchies). $category = get_the_category(); $ancestors = get_ancestors( $category[0]->term_id, ‘category’ ); $direct_parent_id = $ancestors[0]; If you want to get the … Read more

PHP displaying wrong custom taxonomy images

I think (at least part of) the problem is that you’ve got a nested loop where you don’t really need one. The output of get_terms() is an array of objects. So $categories should be an array of objects. You loop through this array of objects here: foreach ( $categories as $category ) { $id = … Read more

Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?

To cut a long story short the answer to the question is Yes. In the end I was able to create: tax-1/tax-2/cpt-1/cpt-1-post/cpt-2/cpt-2-post/ and another structure: tax-1/tax-2/cpt-1/cpt-1-post/cpt-2/custom-field/cpt-2-post/ I used Types from http://wp-types.com/ to create the hierarchical custom taxonomy, the custom post types, custom fields, but most importantly the parent/child relationship between custom post types. That plugin … Read more

Creating custom post type and taxonomy archives and pretty URLs

To achieve permalinks like http://example.com/localpage/%post_name%/, you will need to set the rewrite argument when registering the custom post type: $annoucement_args = array( … ‘rewrite’ => array( ‘with_front’ => false ), … ); I don’t think that using custom taxonomies is the best idea here. Why not use custom meta boxes instead? See this WP Explorer … Read more