Creating custom post type with custom taxonomy and custom fields programatically

Create Custom Post Type function create_product() { $labels = array( ‘name’ => _x( ‘Product’, ‘post type general name’, ‘stacy’ ), ‘singular_name’ => _x( ‘product’, ‘post type singular name’, ‘stacy’ ), ‘menu_name’ => _x( ‘Products’, ‘admin menu’, ‘stacy’ ), ‘name_admin_bar’ => _x( ‘Product’, ‘add new on admin bar’, ‘stacy’ ), ‘add_new’ => _x( ‘Add New’, ‘product’, … Read more

How to add and clear custom post types and taxonomies in a plugin? Considerations for existing data

Custom post types and taxonomies can be registered using register_post_type() and register_taxonomy(). These functions do not actually create any data in the database. Data is added when users populate content (posts and taxonomies). When a plugin is disabled, any post types and taxonomies that it registers will be unregistered, but all of their data in … Read more

Loop through custom posts by taxonomy and display the titles in a list, it is repeating 8 times

You’ve hard-coded the term into the second query. Of course you are seeing the same thing every time: $terms = get_terms( ‘model’, array( ‘orderby’ => ‘count’, ‘hide_empty’ => 0 ) ); if (!is_wp_error($terms)) { foreach( $terms as $term ) { // Define the query $args = array( ‘post_type’ => ‘peterbilt’, ‘tax_query’ => array( array( ‘taxonomy’ … Read more

term_exists() returning NULL on term that exists

The third argument for term_exists() is an integer, not an array. Parameters $term (integer|string) (required) The term to check Default: None $taxonomy (string) (optional) The taxonomy name to use Default: ” $parent (integer) (optional) $parent ID of parent term under which to confine the exists search Default: 0 Pass the correct arguments and it works. … Read more

Hide specific taxonomies from a taxonomy list using ‘get_object_taxonomies’

Try this: <?php $object=”post”; $output=”objects”; $taxonomies = get_object_taxonomies( $object, $output ); $exclude = array( ‘post_tag’, ‘post_format’ ); if ( $taxonomies ) { foreach ( $taxonomies as $taxonomy ) { if( in_array( $taxonomy->name, $exclude ) ) { continue; } $terms = get_terms( array( ‘taxonomy’ => $taxonomy->name, ‘hide_empty’ => true, ) ); if ( ! empty( $terms … Read more