WordPress.org

Ready to get started?Download WordPress

Forums

GYS Themed Categories
Trying to get GYS Themed Categories to work with custom taxonomy (3 posts)

  1. mobiousdesign
    Member
    Posted 1 year ago #

    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.

    Any thoughts?

    http://wordpress.org/extend/plugins/gys-themed-categories-2/

  2. Luke Rumley
    Member
    Plugin Author

    Posted 1 year ago #

    A quick clarification before I dive in: you used "category" as your custom taxonomy?

  3. mobiousdesign
    Member
    Posted 1 year ago #

    no, product_category is the custom taxonomy...I came REALLY close with getting it to work. And made some changes since I posted this. I stepped through the code on a page with a post type of product, and a taxonomy of product_category. And it was pulling the correct child theme...but at the last step...it would not return the stylesheet...

    Here's the entirety of what i updated:

    http://codepad.org/HPyAJoIv

    Some changes I made as I stated above...getting post id with bwp_url_to_postid (and that function is in the codepad...that works...changed the breakout from

    elseif ($pid !=0 && get_post_type($pid) != "page") {

    to

    if ($pid!=0 && 'product' == get_post_type($pid)) {

    Which I know makes this only useable for THAT post type...and I was thinking of adding an option to either pass the post type in...or select it on an options page...but that was a later thing...

    I can also put up a quick test site to play with, just let me know....I did ultimately go with a different solution for this project...but I would REALLY like to be able to do this in the future. And, I'm stubborn and hate getting stumped ;)

    Cheers,

    Brian

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic