I've been trying to get this to work with custom taxonomies...and wonder if anyone has any thoughts:
The original gets the post id and the cat id this way:
// get Post ID from URL $pid=url_to_postid($url); // get Category ID from URL list($url)=explode('/page/',$url); // <- added for paging compatibility $cid=get_category_by_path($url,false); $cid=$cid->cat_ID;
Since I'm trying to get this with a custom post type I can't use url_to_postid so now I'm using bwp_url_to_postid
// get Post ID from URL with bwp_url_to_postid $pid=bwp_url_to_postid($url);
This pulls the Post_ID from the URL even in a custom post type just fine.
So I've gotten the post id, and then, based on that trying to get the cat id (on the assumption that there is only 1 category)
Next instead of getting the $cid (category id) with get_category_by_path, I'd like to get it with the Post ID (again, going on the assumption that there will only ever be 1 category) because of how the permalinks are set...wont see the category in the url.
So my first attempt is wp_get_object_terms
$terms = wp_get_object_terms( $pid, 'product_category', array('fields'=>'ids')) $ids = wp_list_pluck( $terms, 'term_id' ); $cid = array_pop($ids)
Except that $cid isn't pulling the term_id from the current post this way…which is what I expected.
If I manually set $cid in the plugin...it works fine...so it's just a matter of getting the correct term_id from the current post to continue.