Viewing 15 replies - 1 through 15 (of 36 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Chances are those widgets aren’t set to query for anything beyond the post post type by default, but may offer filters to adjust the query arguments.

    For example, the WP Widget Archives has the following filters that you can use to adjust arguments for the wp_get_archives() function.

    widget_archives_dropdown_args — If you’re using the dropdown
    widget_archives_args

    Similar for the Categories widget.

    widget_categories_dropdown_args — uses wp_dropdown_categories()
    widget_categories_args — uses wp_list_categories()

    We don’t do any interaction with these widgets with the plugin, so there is need to do some extra customization on the site owner’s part.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    any changes or new developments with this one @benjino ?

    Thread Starter benjammin

    (@benjino)

    Not yet, I hope to give some attention to seeing if these args can work soon.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Cheers. Just wanted to check in.

    We’ll be around when you get back to it.

    Thread Starter benjammin

    (@benjino)

    Michael I’ve tried to research and figure this out but to no avail. I don’t know PHP enough to workout a proper function for this.

    I have found this snippet for Recent Posts widget and it works. It brings in all posts, default and the CPT. But then I thought it might work for the filters you have shared but don’t know enough to get it work. The second code snippet below breaks the site, makes a completely white screen.

    /**
     * Add CPTs to recent posts widget
     *
     * @param array $args default widget args.
     * @return array $args filtered args.
     */
    function wpigw_recent_posts_args($args) {
        $args['post_type'] = array('post', 'ig_topics');
        return $args;
    }
    add_filter( 'widget_posts_args', 'wpigw_recent_posts_args');
    /**
     * Add CPTs to recent categories widget
     *
     * @param array $args default widget args.
     * @return array $args filtered args.
     */
    function wp_dropdown_categories($args) {
        $args['post_type'] = array('post', 'ig_topics');
        return $args;
    }
    add_filter( 'widget_post_args', 'wp_dropdown_categories');
    • This reply was modified 6 years, 1 month ago by benjammin.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If both of those snippets are your own functions, then the whitescreen is very likely due to the fact that wp_dropdown_categories is already an existing function within WordPress core. Perhaps rename it to wpigw_dropdown_categories or similar.

    function wpigw_dropdown_categories($args) {
        $args['post_type'] = array('post', 'ig_topics');
        return $args;
    }
    add_filter( 'widget_post_args', 'wpigw_dropdown_categories');
    
    Thread Starter benjammin

    (@benjino)

    “topics” is the taxonomy for the custom post type ig_topics.

    So all of the categories for ig_topics are in topics.

    Should “array(‘post’, ‘ig_topics’);” be “array(‘taxonmy’, ‘topics’); ???

    I’ve tried a number of different things with the function “wpigw_dropdown_categories” and nothing is showing up, and nothing is breaking either.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I think I need to step back a moment and re-align.

    One of your examples from earlier relates to the “Recent Posts” widget. Everything I can see with that should be fine.

    However, I’m thinking about my previous answers in relation to your comments previously. The “Categories” widget is meant to show just the category terms. I’m presently wondering if you were referring to when you clicked on a given category, you were only seeing posts from the “post” post type listed, and wanted both. If accurate, then for that we don’t need to be mucking around with widget settings/configuration, we need to simply get the ig_topics into the category archives.

    Before I type up info about that, can you confirm that I’m thinking accurately with this part?

    Thread Starter benjammin

    (@benjino)

    This issue I’m having is with the Category Search widget. I have it set to be a dropdown and show the post count for each category. So the CPT is ig_topics and its taxonomy is topics, where in topics all of the category terms are. I also want to use the CPT Archives widget as well. The category terms show in the dropdown but when I select any one of them the page does not change, the page will refresh but the desired content won’t show. The page just stays the same.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not familiar with a Category Search widget. Just this one at the moment: https://cloudup.com/cK66OPG6p0i in case that’s not the same.

    That one shown in the screenshot is able to switch the taxonomy it uses, but that’s still only going to show the terms and links to those terms’ archives.

    It’s no one’s fault here, but it feels like the situation is becoming more confusing/tangled rather than less, simply because we’re trying to address so many moving parts. Specifically: which widget(s) we’re attempting to use plus whether or not those are from WordPress core or a different plugin, what post types ultimately need to be queried for, and what taxonomies we’re dealing with for each of the previous items.

    Thread Starter benjammin

    (@benjino)

    It’s this plugin: https://www.ads-software.com/plugins/custom-post-type-widgets/

    This supposedly picks up the CPTs single posts, taxonomy and archives. It has similar widgets to the default WP search widgets. For me, the Category search widget is showing all of the categories for the CPT but when I select any of them in the dropdown list the filtering isn’t working.

    Thread Starter benjammin

    (@benjino)

    I really appreciate all your effort to help!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Alright, I’ve been looking over their code, so that I can better provide answers.

    “Categories (Custom Post Type)” widget.

    This is basically a clone of the default one that comes with WordPress core, with the exception of it it provides the ability to select the taxonomy to use, instead of having it default to category or changing via code/filter. With that, it does simply and only provide links to each term’s archive url. This also means that unless the category archives are being told to include your custom post types, it’s not going to show them. They don’t explain this, or at least not very well.

    We do have a quick docs page up regarding adding custom post types to category AND tag archives as you need. It can be found over at https://docs.pluginize.com/article/17-post-types-in-category-tag-archives

    At least for my quick test with this categories widget, the dropdown does switch me to the chosen term. I don’t know why it may not be for you, or maybe it is and you’re not quite recognizing the change, in the event they’re always pulling up no results. Your URL address bar will help indicate if you’re on a different archive.

    If I’ve followed everything accurately after the last few replies, and with a review of what your linked to plugin does, I think you’ll be good to go, or at least off to a much better start, once you utilize the sample code in the Pluginize Docs article.

    Thread Starter benjammin

    (@benjino)

    Michael,

    It’s been a while, I’m back at this.
    I do appreciate your help.
    Before your last post I did have that code found under the page heading “Adding all CPTUI post types to the archives,” found at the link you provided, in my functions.php file. With it there it doesn’t take me to any of the archives for the CPT; the browser URL does not change, the same page I am on refreshes.
    Do I need to add the CPT archive slug to code snippet as a value?

    • This reply was modified 5 years, 11 months ago by benjammin.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If you are/were using the first codeblock from that link, then it’d already be taking care of all your post types registered with CPTUI, and affecting both the category and tag archives. If you used the second code block, then you would need to edit this line to include the post type slugs you’re wanting:

    $cptui_post_types = array( 'my_post_type', 'my_other_post_type' );
    

    Visually not much should be changing, but the results in the archives for those should be growing depending on how many posts you have with matching categories or tags, because it should also be querying for and displaying those extra post types if they indeed match the requirements.

Viewing 15 replies - 1 through 15 (of 36 total)
  • The topic ‘Get CPT Categories and Archives to show in WP Category and Archive Widgets’ is closed to new replies.