Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Ikramy,

    What do you mean exactly? Are you talking about the products page in WooCommerce itself? What are you trying to do?

    Thread Starter ikramy

    (@ikramy)

    Hi Minion,

    First off, thanks for responding.

    Yes, I’m talking about the WooCommerce products page in the WP admin.

    I added a custom field (“_userid”) to the products page where I manually enter the user ID that can manage this product.

    Now, when a user logs in to WP admin, I need to show him the products that have his ID only.

    In other words I need to adjust the products query where statement to match the new criteria.

    Please let me know if this not clear.

    Thanks

    Thread Starter ikramy

    (@ikramy)

    I found the solution ??

    function my_pre_get_posts($query) {
    
    if ( is_admin() && $query->is_main_query() ){
    $query->set(
                        'meta_query', array(
                        array(
                            'key' => '_userid',
                            'value' => get_current_user_id( ),
                            'compare' => '='
                            ))
                    );
    }
    
    }
    
    add_action('pre_get_posts','my_pre_get_posts');

    Thanks

    Ah thats great, thanks for the feedback. Sorry I missed your reply ??

    Thread Starter ikramy

    (@ikramy)

    No worries ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Modify admin products query’ is closed to new replies.