• Resolved klivie

    (@klivie)


    So the page above is an archive (Announcement post type) page for our post type but for some reason it’s displaying the incorrect sidebar.

    In the sidebar settings we’ve created a “Comings & Goings Sidebar” which has it’s sidebar location set as “As Main Sidebar for selected Archive Types” & “Announcement Archive” is selected.

    More curiously, it only displays the incorrect sidebar when there are 0 results in the listings page. If I publish a post under this post type than the correct one is displayed.

    Although this page may sometimes be blank so we need this fixed.

    Any suggestions?

    Thanks,
    Kurt

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello @klivie,

    Hope you’re doing well!

    I’ve tested this and could replicate the issue. I’ve forwarded this to our developers as a bug.

    Thank you for letting us know about this issue.

    Have a good day and take care!

    Kind regards,
    Nastia

    Hello there @klivie,

    I trust you’re doing well!

    Please try the following workaround. Add the code to the functions.php of your child theme or as mu-plugin.

    add_filter( 'cs_replace_post_type', function( $post_type, $replace_type ){
    
        if ( 'archive' == $replace_type && empty( $post_type ) ) {
    
            $queried_object = get_queried_object();
    
            if ( isset( $queried_object->name ) ) {
                $post_type = $queried_object->name;
            }
    
        }
    
        return $post_type;
    }, 20, 2 );

    If you have no child theme, please see here How to Create a WordPress Child Theme.

    Or else, to add is as mu-plugin, please create mu-plugins folder in /wp-content/ directory. Create a blank file using a text editor and name it cs-replace-post-type.php.

    On the forst line please add <?php and then the rest of the code. Save and upload the file to the /wp-content/mu-plugins/ directory.

    Let us know how it went!

    Kind regards,
    Nastia

    Thread Starter klivie

    (@klivie)

    Hi @wpmudev-support9

    Thanks for the response!

    I just added your filter and it fixed my issue! Thank you!

    I’m assuming this fix will be released as a plugin update in future anyway?

    HI @klivie

    Thanks for confirmation that it works for you and I’m happy to hear it solved the issue!

    The code was provided by our developers and along with other possible updates it’s also undergoing QA tests so I hope it will be included in future versions. For now though, the snippet should work just fine as is 🙂

    Best regards,
    Adam

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Archive – Incorrect sidebar used when 0 posts’ is closed to new replies.