Query custom post type with tags

Have you tried wp_get_post_terms() Example usage: $term_lists = wp_get_post_terms($post_id, ‘product_tag’, array(“fields” => “names”)); I modified your code and got this to work on my site: <ul id=”relatedlist”> <?php $tags = wp_get_post_terms($post_id, ‘product_tag’); if ( $tags ) { $tag_ids = array(); foreach ( $tags as $individual_tag ) array_push($tag_ids,$individual_tag->term_id); $args = array( ‘post_type’ => ‘product’, ‘tax_query’ => … Read more

Am I using the flush_rewrite_rules function in the right place?

Considering WordPress Codex flush_rewrite_rules This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when absolutely necessary.… I’d recommend you to … Read more

current_user_can() return FALSE but debugging says TRUE

The register_post_type() function takes a post type name as argument for map_meta_cap, where the default is post. Take a look at the internals of get_post_type_capabilities() for extended insights. That should help you to understand how it’s meant to be: function get_post_type_capabilities( $args ) { if ( ! is_array( $args->capability_type ) ) $args->capability_type = array( $args->capability_type, … Read more

Plugin: register custom post types, child ready and performance best practices

A few thoughts on your code The conditional function_exists() actually will never work because plugins are loaded first, then child theme functions then parent theme functions. You can just drop these conditional checks. The function_exists() function is basically meant for parent themes and allows for a function to be overridden by plugins or child themes … Read more

How to restrict users and admin from creating new taxonomy terms?

This check: <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?> needs to be satisfied to display the “Add New Category” link. You can set the capabilities for your schedule_day_taxonomy taxonomy, when you register it. Example Only users with the edit_schedule_day_taxonomy capability can edit the taxonomy: add_action( ‘init’, ‘schedule_day_tax_func’ ); function schedule_day_tax_func() { register_taxonomy( ‘schedule_day_taxonomy’, … Read more

Get post from custom post type order by two taxonomies

You’re close, syntax is just slightly off. I can’t quite work out how/what terms you need to query for, but this should be the structure of your arguments: $query = new WP_Query( array( ‘post_type’ => ‘product’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => $ids_of_product_cat_terms, … Read more

Get archive post type name

Use get_queried_object to get information about the current page. if you’re on a single post, it will return the post object if you’re on a page, it will return the page object if you’re on an archive page, it will return the post type object if you’re on a category archive, it will return the … Read more