exclude_post
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
1 changed file
with
17 additions
and
92 deletions
| ... | @@ -10,105 +10,30 @@ function add_attachment_mime_type( $attachment_id ){ | ... | @@ -10,105 +10,30 @@ function add_attachment_mime_type( $attachment_id ){ |
| 10 | 10 | ||
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | function wporg_custom_post_type() { | 13 | function exclude_post( $query ) { |
| 14 | register_post_type('documents', | 14 | if ( $query->is_main_query() ) { |
| 15 | array( | ||
| 16 | 'labels' => array( | ||
| 17 | 'name' => __( 'Documents', 'textdomain' ), | ||
| 18 | 'singular_name' => __( 'Documents', 'textdomain' ), | ||
| 19 | ), | ||
| 20 | 'public' => true, | ||
| 21 | 'has_archive' => true, | ||
| 22 | 'rewrite' => array( 'slug' => 'documents' ), // my custom slug | ||
| 23 | ) | ||
| 24 | ); | ||
| 25 | } | ||
| 26 | //add_action('init', 'wporg_custom_post_type'); | ||
| 27 | 15 | ||
| 28 | function wptp_add_categories_to_attachments() { | ||
| 29 | register_taxonomy_for_object_type( 'category', 'attachment' ); | ||
| 30 | // register_taxonomy_for_object_type( 'continent', 'attachment' ); | ||
| 31 | // register_taxonomy_for_object_type( 'country', 'attachment' ); | ||
| 32 | // register_taxonomy_for_object_type( 'region', 'attachment' ); | ||
| 33 | 16 | ||
| 34 | } | 17 | $meta_query = $query->get('meta_query') ? $query->get('meta_query') : array(); |
| 35 | //add_action( 'init' , 'wptp_add_categories_to_attachments' ); | ||
| 36 | 18 | ||
| 37 | // apply tags to attachments | 19 | // append yours |
| 38 | function wptp_add_tags_to_attachments() { | 20 | $meta_query[] = array( |
| 39 | register_taxonomy_for_object_type( 'post_tag', 'attachment' ); | 21 | 'key' => 'exclude_from_search', // please make sure that key is correct |
| 40 | } | 22 | 'value' => '1', |
| 41 | add_action( 'init' , 'wptp_add_tags_to_attachments' ); | 23 | 'compare' => '!=' // you can also try 'NOT EXISTS' comparison |
| 42 | |||
| 43 | // register new taxonomy which applies to attachments | ||
| 44 | function wptp_add_taxonomy() { | ||
| 45 | $labels = array( | ||
| 46 | 'name' => 'Continent', | ||
| 47 | 'singular_name' => 'Continent', | ||
| 48 | 'search_items' => 'Search Continent', | ||
| 49 | 'all_items' => 'All Continent', | ||
| 50 | 'parent_item' => 'Parent Continent', | ||
| 51 | 'parent_item_colon' => 'Parent Continent:', | ||
| 52 | 'edit_item' => 'Edit Continent', | ||
| 53 | 'update_item' => 'Update Continent', | ||
| 54 | 'add_new_item' => 'Add New Continent', | ||
| 55 | 'new_item_name' => 'New Continent Name', | ||
| 56 | 'menu_name' => 'Continent', | ||
| 57 | ); | 24 | ); |
| 58 | $args = array( | ||
| 59 | 'labels' => $labels, | ||
| 60 | 'hierarchical' => true, | ||
| 61 | 'query_var' => 'true', | ||
| 62 | 'rewrite' => 'true', | ||
| 63 | 'show_admin_column' => 'true', | ||
| 64 | ); | ||
| 65 | register_taxonomy( 'continent',[ 'attachment','documents'], $args ); | ||
| 66 | 25 | ||
| 26 | $query->set('meta_query', $meta_query); | ||
| 67 | 27 | ||
| 68 | $labels = array( | 28 | } |
| 69 | 'name' => 'Region', | 29 | } |
| 70 | 'singular_name' => 'Region', | 30 | add_action( 'pre_get_posts', 'exclude_post' ); |
| 71 | 'search_items' => 'Search Region', | ||
| 72 | 'all_items' => 'All Region', | ||
| 73 | 'parent_item' => 'Parent Region', | ||
| 74 | 'parent_item_colon' => 'Parent Region:', | ||
| 75 | 'edit_item' => 'Edit Region', | ||
| 76 | 'update_item' => 'Update Region', | ||
| 77 | 'add_new_item' => 'Add New Region', | ||
| 78 | 'new_item_name' => 'New Region Name', | ||
| 79 | 'menu_name' => 'Region', | ||
| 80 | ); | ||
| 81 | $args = array( | ||
| 82 | 'labels' => $labels, | ||
| 83 | 'hierarchical' => true, | ||
| 84 | 'query_var' => 'true', | ||
| 85 | 'rewrite' => 'true', | ||
| 86 | 'show_admin_column' => 'true', | ||
| 87 | ); | ||
| 88 | 31 | ||
| 89 | register_taxonomy( 'region',[ 'attachment','documents'], $args ); | ||
| 90 | 32 | ||
| 91 | $labels = array( | ||
| 92 | 'name' => 'Country', | ||
| 93 | 'singular_name' => 'Country', | ||
| 94 | 'search_items' => 'Search Country', | ||
| 95 | 'all_items' => 'All Country', | ||
| 96 | 'parent_item' => 'Parent Country', | ||
| 97 | 'parent_item_colon' => 'Parent Country:', | ||
| 98 | 'edit_item' => 'Edit Country', | ||
| 99 | 'update_item' => 'Update Country', | ||
| 100 | 'add_new_item' => 'Add New Country', | ||
| 101 | 'new_item_name' => 'New Country Name', | ||
| 102 | 'menu_name' => 'Country', | ||
| 103 | ); | ||
| 104 | $args = array( | ||
| 105 | 'labels' => $labels, | ||
| 106 | 'hierarchical' => true, | ||
| 107 | 'query_var' => 'true', | ||
| 108 | 'rewrite' => 'true', | ||
| 109 | 'show_admin_column' => 'true', | ||
| 110 | ); | ||
| 111 | register_taxonomy( 'country',[ 'attachment','documents'], $args ); | ||
| 112 | 33 | ||
| 34 | |||
| 35 | // apply tags to attachments | ||
| 36 | function wptp_add_tags_to_attachments() { | ||
| 37 | register_taxonomy_for_object_type( 'post_tag', 'attachment' ); | ||
| 113 | } | 38 | } |
| 114 | //add_action( 'init', 'wptp_add_taxonomy' , 0 ); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 39 | add_action( 'init' , 'wptp_add_tags_to_attachments' ); | ... | ... |
-
Please register or sign in to post a comment