Sort by Featured products, shows some which are not

  • I’ve added the code below to my functions.php to make it possible to ‘sort by featured’. Although, some items do show up which are not marked as featured. I can’t figure out why the keep showing op when filtering on featured. Could there be something else why they keep showing up?

    function wpa104537_filter_products_by_featured_status() {
    
         global $typenow, $wp_query;
    
        if ($typenow=='product') :
    
            // Featured/ Not Featured
            $output .= "<select name='featured_status' id='dropdown_featured_status'>";
            $output .= '<option value="">'.__( 'Show All Featured Statuses', 'woocommerce' ).'</option>';
    
            $output .="<option value='featured' ";
            if ( isset( $_GET['featured_status'] ) ) $output .= selected('featured', $_GET['featured_status'], false);
            $output .=">".__( 'Featured', 'woocommerce' )."</option>";
    
            $output .="<option value='normal' ";
            if ( isset( $_GET['featured_status'] ) ) $output .= selected('normal', $_GET['featured_status'], false);
            $output .=">".__( 'Not Featured', 'woocommerce' )."</option>";
    
            $output .="</select>";
    
            echo $output;
        endif;
    }
    add_action('restrict_manage_posts', 'wpa104537_filter_products_by_featured_status');
    
    function wpa104537_featured_products_admin_filter_query( $query ) {
        global $typenow;
    
        if ( $typenow == 'product' ) {
    
            // Subtypes
            if ( ! empty( $_GET['featured_status'] ) ) {
                if ( $_GET['featured_status'] == 'featured' ) {
                    $query->query_vars['tax_query'][] = array(
                        'taxonomy' => 'product_visibility',
                        'field'    => 'slug',
                        'terms'    => 'featured',
                    );
                } elseif ( $_GET['featured_status'] == 'normal' ) {
                    $query->query_vars['tax_query'][] = array(
                        'taxonomy' => 'product_visibility',
                        'field'    => 'slug',
                        'terms'    => 'featured',
                        'operator' => 'NOT IN',
                    );
                }
            }
    
        }
    
    }
    add_filter( 'parse_query', 'wpa104537_featured_products_admin_filter_query' );

    The blog I need help with is: (visible only to logged in users)

  • It’s not ‘The blog I need help with is bokdem.wordpress.com.’, this was added automatically…

  • Hi bokdem

    Can you please let us know the site URL for which you need help?

    I think Your site is using WordPress.org software which is hosted on another host. So WordPress.com forum is not the right place to get the solution for your question.

    You can post your question in WordPress.org forum:
    https://wordpress.org/support/forums/

    For more information here is the support documentation link below:
    https://codex.wordpress.org/

    WordPress.com forum helps the sites hosted on WordPress.com only

    WordPress.com and WordPress.org are both different platforms, you can find more information for this here:

    WordPress.com vs. WordPress.org

    You’ll need a free WordPress.org account to post – if you don’t already have one, you can register here:
    https://wordpress.org/support/register.php

    Hope this helps

  • The topic ‘Sort by Featured products, shows some which are not’ is closed to new replies.