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

  • ukdesignservices
    Participant
    # 3 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
    # 3 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
    # 3 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
    # 3 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
    # 3 months ago

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

    ukdesignservices
    Participant
    # 3 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
    # 3 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
    # 3 months ago

    Thank you, I’ll try that.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.