Show category only if post type is post_three

you can modify your get_categories function call to include the tax_query parameter to specify the taxonomy and terms you want to retrieve.

I have added the taxonomy parameter to specify that we are querying categories from the category taxonomy.

The object_type parameter restricts the query to only categories associated with the post_three post type

<aside class="sidebar">
    <div class="widget widget-filter">
        <button class="widget-title">Explore Topics</button>
        <svg class="separator" viewBox="0 0 238 11" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg">
            <line opacity="0.3" y1="0.5" x2="101.942" y2="0.5" stroke="#3CD5AF"></line>
            <line opacity="0.3" y1="10.5" x2="237.5" y2="10.5" stroke="#3CD5AF"></line>
        </svg>
        <?php 
        // Retrieve categories associated with the 'post_three' post type
        $categories = get_categories(array(
            'taxonomy' => 'category', // Specify the taxonomy
            'object_type' => array('post_three'), // Specify the post type
            'hide_empty' => true,
        )); ?>
        <ul class="filter-list">
            <?php foreach ($categories as $category) : ?>
                <li>
                    <a href="<?= get_category_link($category->term_id); ?>"><?= esc_html($category->name); ?></a>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
</aside>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)