• Resolved Dalton Rooney

    (@daltonrooney)


    I have a site in development with an interesting custom post type arrangement. So far, I haven’t found a way to get Breadcrumb NavXT to do what I want, I was hoping someone could help.

    The site has the following post types: page, post, private-page, private-post

    The titles should be self-explanatory, the “private” versions of page and post are CPTs that are only accessible to logged in visitors. I set it up this way to simplify administration for my client, since the entire “private” section has it’s own complex sitemap in addition to the public sitemap.

    The private-page CPT is hierarchical and the root is set to a page called “members”. The private-post CPT is non-hierarchical and the root should be under the private-page called “news”.

    Example private-page: https://example.com/members/resources/handbook
    Example private-post: https://example.com/members/news/single-private-post

    Problem 1: NavXT doesn’t seem to respect the hierarchy of my private-page CPT. With the example private page, where members is the root, and resources and handbook are the hierarchical CPT. Logically, the breadcrumb trail should be Home | Members | Resources | Handbook.

    Instead I get Home | Members | Handbook. NavXT doesn’t seem to respect the CPT hierarchy. Is this the expected behavior or is something wrong with my config?

    Problem 2: I need to set a private-page as the root for my private-post CPT, but NavXT doesn’t have an admin feature to support this. Is there a simple bit of code to enable this?

    Thanks for your help! I love this plugin and have used it a few times now.

    Cheers,
    Dalton

    https://www.ads-software.com/plugins/breadcrumb-navxt/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Dalton Rooney

    (@daltonrooney)

    Just a follow up to my previous post, I did figure out the answer to problem 1. In the plugin settings for the custom post type, there is an option called “%Post Type% Hierarchy Display”, but the available choice is “Show the taxonomy leading to a private page in the breadcrumb trail.”

    I had not selected this option because I am not using a taxonomy with this particular CPT. Selecting this option does enable the post type hierarchy in the breadcrumb trail, so I guess this is just some feedback on the wording of that option – I personally found it very confusing, and did not understand what it did until I was looking through the post_hierarchy function in the plugin code.

    Perhaps better wording for that option would be “Show the taxonomy or hierarchy leading to a %post type% in the breadcrumb trail.”

    For problem 2, I’m still looking for a way to set a custom post type as the root for another post type. I’ve done it by editing the database directly, but that change is lost as soon as the options page is saved again. I’m sure I can do it with the help of some filter or action, I’ll keep digging.

    Thanks!
    Dalton

    Plugin Author John Havlik

    (@mtekk)

    For the first problem, thanks for pointing out the goofy wording. I hadn’t noticed that (and it is misleading). I must have missed that when it and it’s associated option was changed to “hierarchy” from “taxonomy”. I’ll get that fixed for the next release.

    For the second problem, the only reserved type for roots is pages (at least for the settings page). However, as you have found out, this can be overridden. Rather than directly modifying the database option (which you acknowledge is problematic), what you want to do is hook into the bcn_settings_init filter (see the Breadcrumb NavXT Documentation for more information on this filter). The filter will pass in the $opts array look for the key apost_{post_type_name}_root (where you replace {post_type_name} with the post type name in question) and set it to the ID of the post (page, custom post type instance) that you want.

    Plugin Author John Havlik

    (@mtekk)

    Btw, I am tracking the first problem in this GitHub issue: https://github.com/mtekk/Breadcrumb-NavXT/issues/95

    Thread Starter Dalton Rooney

    (@daltonrooney)

    Thank you John, I really appreciate your help with this.

    I’ve tried the bcn_settings_init filter without any luck. Here’s the code I’m using:

    add_filter('bcn_settings_init', 'set_private_post_root');
    function set_private_post_root($options) {
      $options['apost_private-post_root'] = 221;
      return $options;
    }

    If I do a var_dump on the $options array after I set it, the value looks correct, but the breadcrumb continues to use the value from the database. Am I missing something?

    Plugin Author John Havlik

    (@mtekk)

    Sorry, I lead you down the wrong path, that filter is only going to work for settings that don’t already exist in the $opt array (e.g. for extension plugins adding their own settings). You can do something similar by hooking into the option_bcn_options filter (part of WordPress). You should be able to use the same function you have above, but just change filter hooked it hooks into.

    Thread Starter Dalton Rooney

    (@daltonrooney)

    Whoa, I had no idea about the option_ filters, that just blew my mind. Worked perfectly, thank you! And I will probably use that a lot.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hierarchical custom post type help needed’ is closed to new replies.