How do you get facet widgets to appear on a custom post type / taxonomy page?

  • ukdesignservices
    Participant
    # 2 years, 11 months ago

    Is it possible to get the facets and sort widgets to appear on custom post type taxonomy pages?
    I’ve systematically tried every ‘Replace WordPress archives’ option, updating my permalinks each time, but the sidebar fails to render any widgets? I’m trying to add filtering to my product taxonomies.

    Many thanks

    wpsolr
    Keymaster
    # 2 years, 11 months ago

    Yes, it is possible to display our 2 widgets, facets and sort, on custom post type archives.

    You just need to select “Custom post type” in screen 2.1:

    Replace WP search on all archive pages

    ukdesignservices
    Participant
    # 2 years, 11 months ago

    Thanks for your reply. Unfortunately this is not working for me. I have checked ‘Custom post types’ in screen 2.1 but neither the sort or facets widgets are rendering.

    Debugging, I can see that:

    return self::$is_replace_by_wpsolr_query; returns false before checking WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_post_type()

    Any idea how I can fix this?

    Many thanks

    ukdesignservices
    Participant
    # 2 years, 11 months ago

    Okay, I think I’ve found the issue. It looks like it will work on an archive of all posts of a given type, but not on a taxonomy term.

    Could you advise on how to extend get_is_replace_by_wpsolr_query() to include a condition for:

    $is_replace_by_wpsolr_query = (is_archive() && is_tax());

    Many thanks

    wpsolr
    Keymaster
    # 2 years, 11 months ago

    It is already replacing Categories and terms. Just check the 2 options in screen 2.1

    ukdesignservices
    Participant
    # 2 years, 11 months ago

    Thanks but unfortunately that’s not making any difference.

    I have tried with everything checked:
    https://www.dropbox.com/s/sc19dc127dhi607/replace-archives.PNG?dl=0
    but the widgets are still not rendering.

    Looking at get_is_replace_by_wpsolr_query():

    $is_replace_by_wpsolr_query = ! is_admin()
    		                 && is_main_query()
    		                 && WPSOLR_Service_Container::getOption()->get_search_is_use_current_theme_search_template();
    
    		if ( $is_replace_by_wpsolr_query ) {
    
    			$is_replace_by_wpsolr_query = false;
    			/**
    			 * Search
    			 */
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_search() ) {
    				$is_replace_by_wpsolr_query = is_search();
    			}
    
    			/**
    			 * WordPress post archives
    			 */
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_home() ) {
    				$is_replace_by_wpsolr_query = is_home();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_author() ) {
    				$is_replace_by_wpsolr_query = is_author();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_year() ) {
    				$is_replace_by_wpsolr_query = is_year();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_month() ) {
    				$is_replace_by_wpsolr_query = is_month();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_day() ) {
    				$is_replace_by_wpsolr_query = is_day();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_category() ) {
    				$is_replace_by_wpsolr_query = is_category();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_tag() ) {
    				$is_replace_by_wpsolr_query = is_tag();
    			}
    
    			if ( ! $is_replace_by_wpsolr_query && WPSOLR_Service_Container::getOption()->get_search_is_replace_default_wp_post_type() ) {
    				$is_replace_by_wpsolr_query = is_post_type_archive();
    			}
    		}

    I don’t see how $is_replace_by_wpsolr_query will ever return true on a custom taxonomy page on a custom post type.

    wpsolr
    Keymaster
    # 2 years, 11 months ago

    $is_replace_by_wpsolr_query = is_category();
    $is_replace_by_wpsolr_query = is_tag();

    but then:
    $is_replace_by_wpsolr_query = apply_filters( WPSOLR_Events::WPSOLR_FILTER_IS_REPLACE_BY_WPSOLR_QUERY, $is_replace_by_wpsolr_query );

    For instance, our WooCommerce extension uses this filter to change the value.

    ukdesignservices
    Participant
    # 2 years, 11 months ago

    Thank you, I’ll try that.

    memphdutch
    Participant
    # 2 years, 2 months ago

    I want to use this with a custom taxonomy. If I created a custom plugin so that I wasn’t editing the actual plugin, what would I need to include prior to these lines of code to help it understand the context? Or is there a better way to do it?

    wpsolr
    Keymaster
    # 2 years, 2 months ago

    Custom taxonomies archives should work already, since https://www.wpsolr.com/forums/topic/release-21-6/

    memphdutch
    Participant
    # 2 years, 2 months ago

    I am using the same template for my search page as well as custom taxonomy archives. The sidebar filters work on the search page but do not work on the custom taxonomy pages. I don’t see in the WPSOLR settings how to make that active. I am on version 21.8 of the plugin.

    Screenshots:

    https://www.dropbox.com/s/t4a6qixgjs4jhvm/Screen%20Shot%202020-04-15%20at%2010.08.46%20AM.png?dl=0

    https://www.dropbox.com/s/9qnwfac9v7hsfem/Screen%20Shot%202020-04-15%20at%2010.08.59%20AM.png?dl=0

    https://www.dropbox.com/s/aqnvf9wdzyz8eya/Screen%20Shot%202020-04-15%20at%2010.09.08%20AM.png?dl=0

    https://www.dropbox.com/s/roq9yje2dxyp2it/Screen%20Shot%202020-04-15%20at%2010.09.30%20AM.png?dl=0

    memphdutch
    Participant
    # 2 years, 2 months ago

    Any thoughts on this? The sidebar facets on my custom taxonomy archives are not working even though they use the identical template to the search page.

    wpsolr
    Keymaster
    # 2 years, 2 months ago

    How did you create your custom taxonomies?

    memphdutch
    Participant
    wpsolr
    Keymaster
    # 2 years, 2 months ago

    Here is a version with a fix to let facets appear on custom taxonomies archives:
    https://www.dropbox.com/s/h3g4lzr3jv2ezwq/wpsolr-pro-fix-missing-custom-tax-archives.zip?dl=0

    Let me know how it goes.

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.