-1

I am working with a multivendor electronic shop.The website has different roles.One of the roles are shop owner.Under this role different electronic shop owner can register.like owners for whirlpool, singer , samsung...etc.

Another function is preorder.Where one customer enters into a shop and through preorder-form they can pre-order different things on that shop.

Now i have a custom post pre-order where all the pre orders are shown in backend.For an administrator he can see all pre orders from all shops i.e: preorders from whirlpool, singer , samsung.

But the problem is to the shop owner.I want to show only preorders from their respective shop.Like preorders from whirlpool to whirlpool shop owner

Is there any way to show in this way in wp admin panel under pre-order post type?


Note : i used user role editor.But its not that what i want.Also i don't want to use plugin


1 Answers1

0

Maybe something like this:

add_filter( 'parse_query', 'pre_order_posts_filter' );

function pre_order_posts_filter( $query ) {

    global $post_type;      

    if ( 'pre-order' == $post_type && is_admin() ) {

        $current_user = wp_get_current_user();

        if ( in_array( 'shop-owner', $current_user->roles ) ) {
            // filter only for user role `shop-owner` (please adjust)
            $query->query_vars['meta_key'] = 'author_id';
            $query->query_vars['meta_value'] = $current_user->ID;               
        }

    }

}

You have to adjust it to your conditions.

Andy Tschiersch
  • 3,716
  • 1
  • 17
  • 24
  • This is an example. I don't know how the pre-orders associated with the shop owners. In my example I assume that the pre-orders have a metakey `shop_owner` that holds the User-ID of the shop-owner. – Andy Tschiersch Nov 25 '16 at 08:27
  • Yes You are absolutely right.It has author_id which is the id of the shop owner.but how i can use it?i.e: suppose author / shop-owner having ID : 1 - logged in and i want to show on `pre-order` page which have only author id: 1 –  Nov 25 '16 at 10:00
  • Yes look at the picture : http://www.awesomescreenshot.com/image/1881164/e1867fa50be5a88786a977bfdcda07e7 –  Nov 25 '16 at 11:47
  • 1
    Then my example should work. Make sure you use the right user role. – Andy Tschiersch Nov 25 '16 at 11:51
  • 1
    One more things please : How can i show only all , pending & published post? look at here : http://www.awesomescreenshot.com/image/1881347/a7210da1d2658901cf437372fa4ea086 –  Nov 25 '16 at 12:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129043/discussion-between-beard-facial-and-andy-tschiersch). –  Nov 25 '16 at 12:58