RaymondVDB

Function to allow more Category Archives for your CPT UI plugin wordpress

Sep 28th, 2022 (edited)
155
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1.  0.57 KB | None |  
  2.      
  3. function my_cptui_add_post_types_to_archives( $query ) {
  4.     // We do not want unintended consequences.
  5.     if ( is_admin() || ! $query->is_main_query() ) {
  6.         return;    
  7.     }
  8.  
  9.     if ( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
  10.  
  11.         // Replace these slugs with the post types you want to include.
  12.         $cptui_post_types = array( 'your_Blog', 'your_blog' );
  13.  
  14.         $query->set(
  15.             'post_type',
  16.             array_merge(
  17.                 array( 'post' ),
  18.                 $cptui_post_types
  19.             )
  20.         );
  21.     }
  22. }
  23. add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );
Advertisement
Comments
  • RaymondVDB
    3 years (edited)
    # text 0.18 KB | 0 0
    1. Paste this function the the functions.php page, save and refresh. This will allow wordpress to give your other blogs the ablity to be sorted by category for your CPT UI plugin wordpress.
Add Comment
Please, Sign In to add comment