Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. $args = array(
  2. 'labels' => $labels,
  3. 'supports' => array( 'title', 'editor' ),
  4. 'hierarchical' => false,
  5. 'public' => true,
  6. 'show_ui' => false,
  7. 'show_in_menu' => false,
  8. 'menu_position' => 5,
  9. 'show_in_admin_bar' => false,
  10. 'show_in_nav_menus' => false,
  11. 'can_export' => true,
  12. 'has_archive' => true,
  13. 'exclude_from_search' => false,
  14. 'publicly_queryable' => true,
  15. 'capability_type' => 'post',
  16. );
  17. register_post_type( 'taxarchive', $args );
  18.  
  19. $taxonomies = $wpdb->get_results("SELECT term_id, name FROM $wpdb->terms");
  20. $taxonomies_array = array();
  21. wp_defer_term_counting(true);
  22. foreach ($taxonomies as $taxonomy) {
  23. $term = get_term($taxonomy->term_id);
  24. $taxonomy = get_taxonomy($term->taxonomy);
  25. if(isset($term->taxonomy) && $taxonomy->publicly_queryable) {
  26. $taxonomies_array[$taxonomy->name] = $term->taxonomy;
  27. $term_post = array(
  28. 'post_title' => $term->name,
  29. 'post_content' => $term->name,
  30. 'post_status' => 'publish',
  31. 'post_type' => 'taxarchive'
  32. );
  33. if(post_exists($term->name) == 0) {
  34. wp_insert_post($term_post);
  35. }
  36.  
  37. }
  38. }
  39.  
  40. wp_defer_term_counting(false);
  41.  
  42. function add_post_type_to_search( $query ) {
  43. if ( is_admin() || ! $query->is_main_query() ) {
  44. return;
  45. }
  46.  
  47. $args = array(
  48. 'exclude_from_search' => false,
  49. );
  50.  
  51. $post_types = get_post_types( $args, 'names', 'and' );
  52. print_r($post_types);
  53.  
  54.  
  55. $query->set(
  56. 'post_type', array_values($post_types)
  57. );
  58. // print_r($query);
  59.  
  60. }
  61. add_filter( 'pre_get_posts', 'add_post_type_to_search' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement