• Resolved crzyhrse

    (@crzyhrse)


    Hello,

    I’ve just discovered that Conditional Widgets is no longer working for me on custom post types, and it seems to have begun real recently, either since your very recent major plugin update and/or since updating the site to WP 4.0, both updates occurring pretty close together in this case…

    So now every activated widget is showing up in the sidebars of every individual custom post, rather than just the specific one or two that are set to be there by using Conditional Widgets’ Post Logic for Categories, with posts in specific custom posts types each having their own category…

    I can’t say for default WP posts, as I am not using them at the moment on this site…

    It was all working fine before the updates… I’ve tried some different settings to try to again remove a couple of widgets from the custom posts, setting Post Logic for Categories both enabled and not enabled, and while enabled both Show with nothing selected and Hide with everything selected…

    Nothing seems to work… In the past I’ve been setting Post Logic for Categories as enabled and hide, and with nothing selected, except when I want something to appear… And everywhere else is set to hide as always, except where the widget is wanted…

    Page Logic seems to be all fine, at least so far, on all the pages with sidebars, including pages on which I’m using Custom Content Shortcode to display different CPTs…

    The CPTs are made with Custom Post Type UI, with nothing unusual about them I don’t believe…

    Hoping this can be sorted out pretty soon, my Individual custom posts’ sidebars are looking pretty weird…

    Kind regards…

    https://www.ads-software.com/plugins/conditional-widgets/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter crzyhrse

    (@crzyhrse)

    I’ve done a little more exploring… the problem occurs on all the individual post pages of every custom post type (presently five)… It does not occur on the individual page of a regular WP post, now that I’ve I created a test post to see…

    Thread Starter crzyhrse

    (@crzyhrse)

    Some more info… I have another site in production, pretty far along, that has now been updated to WP 4.0… Conditional Widgets has not been updated and is still version 1.8.

    And the issue is not happening on this site. Conditional Widgets and its Post Logic for Categories is performing fine in sidebars of single CPTs created using the same Custom Post Type UI…. There is an almost identical set of active plugins on this site, if anything a few more than on the other…

    So I believe that suggests the issue with single CPTs doesn’t have anything directly to do with the WP 4.0 update, but rather with the changes made when Conditional Widgets went to version 2.x..?

    I’ve considered switching back to 1.8 on the site the issue is occurring on, but the changelog says 2.0.1 had a major rewrite and modified how settings are stored, so I would be concerned about issues with the database and the now existing 2.x settings, assuming they are saved when the plugin is deleted… I’d hate to have to reset every widget again, there are lots of instances spread across a bunch of pages… It’d be nice to hear if you think reverting back to 1.8 would be feasible in the short term without a lot of work…? And of course hoping you are looking into this… ??

    Kind regards…

    Heya

    The situation is effectively this: Conditional Widgets was not initially designed to work with post types other than Posts and Pages – the fact that it did work for you was a nice coincidence ?? … up until now anyway.

    Yes, 2.x will break this functionality for you. The good news is that there’s a good chance this can be pretty reasonably addressed in your situation.

    Question: Are you using the logic on both Posts AND your custom post type, or just on your CPT?

    I’ll warn you that I’ve got a pretty full schedule of meetings this week, but hopefully I can squeeze out some time to test it for you.

    Note: If you have a development/test server to play on, and are familiar with using Filters, I think the code should be pretty easy to take a look at and replace Post/Category functionality with CPT/Category functionality with just a line or two from your functions.php

    Regarding downgrading back to 1.8:
    I believe you’d need to redo your logic for each widget if you choose to go that route.

    Thanks for your posts, and I’ll try to look back into this as soon as I can find the time.

    Thread Starter crzyhrse

    (@crzyhrse)

    Heya back and thank you so much for your reply,

    And yes I am just using Custom Post Types not regular WP Posts… I am comfortable and familiar with placing code in functions.php and other files, customizing and creating new page templates, directories etc, lots of child style.css mods, using shortcodes via shortcode plugins, and maybe a little familiar with filters…

    And I can learn what I need to, lots of resources for that… Also I do have development/server testing resources both at the server level and locally with Mamp… Maybe knowing all this will let you feel comfortable putting a bit of time into this…

    I’ll pass on the downgrading and here’s hoping you can devise the code needed, and where to place if there’s any that goes somewhere other than functions.php, though it’s be great if that could be where it all is, as that would mean your future updates would be OK without redoing…

    Conditional Widgets is the very best most intuitive and convenient means that I know of for placing widgets into sidebars conditionally, and I’ve explored a good bit, so really want to stay with it…

    In the future and with this sorted out my very fond regards for Conditional Widgets will be better reflected through some actual reciprocation than they have been up to now… So to speak… ??

    Kind regards…

    If you’re feeling adventurous, try adding this to your functions.php, replacing ‘foo’ with the actual stored name of your custom post type, of course:

    // Add Conditional Widgets support (UI & Logic) for post type ‘foo’ and taxonomy ‘category’

    add_filter(‘conditional_widgets_type_tax_pairs’, ‘foo_conditional_widget_type_tax_pairs’ );

    function foo_conditional_widget_type_tax_pairs( $pairs_array ) {

    $foo_pair = array(‘tax’=>’category’, ‘type’=>’foo’);
    $pairs_array[] = $foo_pair;
    return $pairs_array;

    }

    Untested, but shouldn’t break anything. Got meetings all day so this is the best I can do for now. Let me know how it goes!

    Thread Starter crzyhrse

    (@crzyhrse)

    As you say it didn’t break anything, but didn’t alter anything either… ??

    All caches cleared of course… Cloudflare, Wordfence Falcon, and browser…

    Here is the full of the functions.php in the child directory with the code above added in, so you can see it in context… The Post Type Name is of course “testimonials” without the quotes…

    <?php
    
    /* You can add your own php functions and code snippets below */
    
    /**
    * Separate Media Categories from Post Categories
    * (uses a custom category called 'category_media' for the categories in the media library)
    */
    add_filter( 'wpmediacategory_taxonomy', function(){ return 'category_media'; }, 1 ); //requires PHP 5.3 or newer
    
    /* Additional Contact Form 7 Telephone Number Format Variations
    */
    add_filter( 'wpcf7_is_tel', 'your_custom_wpcf7_is_tel', 10, 2 );
    
    function your_custom_wpcf7_is_tel( $result, $tel ) {
    	$result = preg_match( '/^[\d\s().+-]*$/', $tel );
    	return $result;
    }
    
    // Add Conditional Widgets support (UI & Logic) for post type 'testimonials' and taxonomy 'category'
    
    add_filter('conditional_widgets_type_tax_pairs', 'testimonials_conditional_widget_type_tax_pairs' );
    
    function testimonials_conditional_widget_type_tax_pairs( $pairs_array ) {
    
    $foo_pair = array('tax'=>'category', 'type'=>'testimonials');
    $pairs_array[] = $testimonials_pair;
    return $pairs_array;
    
    }
    
    ?>

    I’m ready to try as many versions as necessary, hoping it will also be helpful to others as well, once it is working… And presumedly one will be able to repeat it again in the functions.php for other CPTs, once it works…?

    Kind regards…

    $foo_pair = array(‘tax’=>’category’, ‘type’=>’testimonials’);
    $pairs_array[] = $testimonials_pair;

    These neither to either both say $foo_pair or both say $testimonials_pair.

    Then you should get options in the widget control panel to select from.

    Thread Starter crzyhrse

    (@crzyhrse)

    Wow, thank you, my eye missed that foo, and it is working awesomely perfectly now, and once again I am amazed at the magic of code…

    With five current CPTs (a couple more likely to come) and a slew of different widget instances across a bunch of pages it took a bit of time to set the added Logic sections up… AND, it works totally cool with multiple CPTs set up through the child functions.php…

    Took a while to sink into the additional variables but as I did I sort of got a glimmer that this could enable some more subtle design possibilities around widget appearances in the future…

    Really grateful for this plugin, and for your attention to it, and for helping this to happen for us…

    Off to reciprocate… ??

    Kind regards…

    Glad it’s working for you.

    The ability to add/modify custom post types / taxonomies to Conditional Widgets was a ‘hidden feature’ in 2.x that I didn’t mention anywhere because I hadn’t had time to properly test/tweak it. I only pushed 2.x out when I did because I wanted to address the other ‘strict’ warnings some people were experiencing.

    Now that you’ve confirmed it’s working, I’ll try to finish up my testing and documentation and let others know. Thanks

    Thread Starter crzyhrse

    (@crzyhrse)

    You are welcome and I’m glad to have been able to be of help that way, and though not presently using tags can see it coming, so will be on the lookout for that documentation… Am assuming it will be similar code placed in the child functions.php file…

    Regards from New Mexico… ??

    Jason – Is this a fix that will be in a future version?

    I ask because we were using this on some custom post types too… unfortunately we have 600+ sites and I can’t possibly go and fix each one individually…

    Let me know! Thanks!

    Thread Starter crzyhrse

    (@crzyhrse)

    Maybe here is a place to put in for a possible future feature request…?

    Our very few sites ?? are presently averaging between 30 and 40 widget instances… In no case are any assigned to all pages, and most by far are assigned to just one or two pages or custom post type categories…

    Especially with this great new ability to include and selectively assign via individual custom post types, and the same ability with tags coming as well it seems, it would be very helpful to be able to globally select so everything is checked/enabled active and all the enabled areas set to show (except for the front page left to hide), but nothing specific selected, and with the hide selections at the bottom checked…

    Basically one could then select the global option at the top, and then just enable specifically for where the widget is needed…

    As it is, and even more so now with all the custom post types added I need to go to each area and check enable it and set it to show, check all the hide boxes everywhere else, and then enable it in the one or two or few places it is intended for…

    I don’t know but, you mentioned that you hesitated to add more things like the custom post types you’ve gratefully made possible in this thread because it could make it overly complicated for a lot of folks…? But maybe this would make it pretty easy even with all the added areas…? Perhaps even a second global that selects for the widget to show everywhere, then go in and turn it off in a just few places perhaps, for widgets that are intended to be more or less site wide…?

    I have no idea how difficult such possibilities might be, so just a suggestion in case it is helpful… I can say for sure these possibilities would be helpful for me… ??

    Kind regards…

    Hello,

    I′m using the same code and the UI appears in the widget section but it doesn’t work when I′m navigating my CPT. I only have one CPT and this is my function.php code, maybe there′s a conflict:

    <?php
    /* ------------------------------------------------------------------------- *
     *  Custom functions
    /* ------------------------------------------------------------------------- */
    
    	// Add your custom functions here, or overwrite existing ones. Read more how to use:
    	// https://codex.www.ads-software.com/Child_Themes
    
    function namespace_add_custom_types( $query ) {
      if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
         'post', 'nav_menu_item', 'destinos'
    		));
    	  return $query;
    	}
    }
    add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
    
    // Add Conditional Widgets support (UI & Logic) for post type 'destinos' and taxonomy 'category'
    
    add_filter('conditional_widgets_type_tax_pairs', 'destinos_conditional_widget_type_tax_pairs' );
    
    function destinos_conditional_widget_type_tax_pairs( $pairs_array ) {
    
    $destinos_pair = array('tax'=>'category', 'type'=>'destinos');
    $pairs_array[] = $destinos_pair;
    return $pairs_array;
    
    }

    Help is more than welcome, I tryed other plugins but this one is easier to use and more User Friendly.

    Thread Starter crzyhrse

    (@crzyhrse)

    Hi,

    It is working great here for me, with six CPTs so far… Your code for the Conditional Widgets support for the CPTs is the same as mine… What I believe is different is that I am using the plugin Custom Post Types UI to create my CPTs, rather than adding code into the Child’s functions.php to create them, as you seem to have done here… I don’t write code so can’t say about your code for that… Custom Post Types UI is a really great plugin…

    Hoping this might helpful…

    Kind regards…

    Hi crzyhrse,

    Thanks, I am using PODs Framework and the other code is to output my CPT in categories, tags and so on. I don’t understand about code too, but I think that it cannot be causing the troubles.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘No longer working for Custom Post Types sidebars…’ is closed to new replies.