This time, I helped a customer in Beijing develop an enterprise application using wordpress, which is very similar to erp. I used wordpress for erp for the first time, and there are still many strange requirements.
For example, in supplier management, I made the supplier a custom content type. Custom categories are also included in the custom type. You need to display a filter for the custom category, such as the default monthly category.
After searching for a long time, I finally found the following code to solve the problem. I used a wordpress action and a filter)
The code is as follows: |
Copy code |
Function work_restrict_manage_posts (){ Global $ typenow; $ Args = array ('public' => true, '_ builtin' => false ); $ Post_types = get_post_types ($ args ); If (in_array ($ typenow, $ post_types )){ $ Filters = get_object_taxonomies ($ typenow ); Foreach ($ filters as $ tax_slug ){ $ Tax_obj = get_taxonomy ($ tax_slug ); Wp_dropdown_categories (array ( 'Show _ option_all '=> _ ('all'. $ tax_obj-> label ), 'Taxonomy' => $ tax_slug, 'Name' => $ tax_obj-> name, 'Orderby' => 'term _ order ', 'Selected' => $ _ GET [$ tax_obj-> query_var], 'Hierarchical '=> $ tax_obj-> hierarchical, 'Show _ count' => false, 'Hide _ empty' => false )); } } } Function work_convert_restrict ($ query ){ Global $ pagenow; Global $ typenow; If ($ pagenow = 'edit. Php '){ $ Filters = get_object_taxonomies ($ typenow ); Foreach ($ filters as $ tax_slug ){ $ Var = & $ query-> query_vars [$ tax_slug]; If (isset ($ var) & $ var> 0 ){ $ Term = get_term_by ('id', $ var, $ tax_slug ); $ Var = $ term-> slug; } } } Return $ query; } Add_action ('restrict _ manage_posts ', 'work _ restrict_manage_posts '); Add_filter ('parse _ query', 'work _ convert_restrict '); |