1<?php23add_action('pre_get_posts',function($query){4if($query->is_admin){5returnfalse;6}78$is_client_tax=$query->get('client');9$is_post_type_work='work'===$query->get('post_type');10$is_category=$query->is_category;11$is_coding_category=$is_category&&'coding'===$query->get('category_name');12$is_design_category=$is_category&&'design'===$query->get('category_name');1314if($is_client_tax||$is_post_type_work||$is_coding_category||$is_design_category){15$users=array(16// タクソノミーのターム名を Basic 認証のユーザー名にしておく.17'foo client'=>'password for foo client',18'bar client'=>'password for bar client',19'baz'=>'password for baz',20);2122// https://www.webantena.net/wordpress/functions-php-basic-auth-custom-post-type/ の basic_auth を参照.23$basic_auth_username=basic_auth($users);2425$tax_query=array(26array(27'taxonomy'=>'client',28'field'=>'name',29'terms'=>$basic_auth_username,30),31);3233$query->set('tax_query',$tax_query);34$query->set('post_type',array('work'));35}36});
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/14 08:08