Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FAQS CPT
- add_action( 'init', 'spc_faqs_custom_post_type' );
- function spc_faqs_custom_post_type()
- {
- register_post_type( 'faqs',
- array('labels' =>
- array(
- 'name' => __( 'FAQs' ),
- 'singular_name' => __( 'faqs' ),
- 'menu_name' => __( 'FAQs' ),
- 'all_items' => __( 'All FAQs' ),
- 'add_new' => __( 'Add New FAQ' ),
- 'add_new_item' => __( 'Add New Page to the FAQs' ),
- 'edit_item' => __( 'Edit Page - faqs' ),
- 'new_item' => __( 'Add New Page - faqs' ),
- 'view_item' => __( 'View Page' ),
- 'search_items' => __( 'Search faqs' ),
- 'not_found' => __( 'No pages found' ),
- 'not_found_in_trash' => __( 'No pages found in trash' )
- ),
- 'public' => true,
- 'hierarchical' => true,
- 'has_archive' => true,
- 'exclude_from_search' => true,
- 'menu_icon' => 'dashicons-feedback',
- 'supports' =>
- array(
- 'title',
- 'editor',
- 'page-attributes',
- 'thumbnail',
- 'custom-fields',
- 'revisions',
- ),
- 'capability_type' => 'post',
- 'rewrite' => array(
- 'slug' => 'faqs',
- 'with_front' => false // Permalinks format
- ),
- 'show_ui' => true,
- 'show_in_nav_menus' => true,
- 'show_in_menu' => true,
- 'menu_position' => 4,
- )
- );
- }
- // FAQS Taxes
- if ( ! function_exists( 'faq_taxonomy' ) ) {
- // Register Custom Taxonomy
- function faq_taxonomy() {
- $labels = array(
- 'name' => _x( 'FAQ Categories', 'Taxonomy General Name', 'text_domain' ),
- 'singular_name' => _x( 'FAQ Category', 'Taxonomy Singular Name', 'text_domain' ),
- 'menu_name' => __( 'FAQ Categories', 'text_domain' ),
- 'all_items' => __( 'All FAQ Categories', 'text_domain' ),
- 'parent_item' => __( 'Parent FAQ Category', 'text_domain' ),
- 'parent_item_colon' => __( 'Parent FAQ Category:', 'text_domain' ),
- 'new_item_name' => __( 'New FAQ Category', 'text_domain' ),
- 'add_new_item' => __( 'Add New FAQ Category', 'text_domain' ),
- 'edit_item' => __( 'Edit FAQ Category', 'text_domain' ),
- 'update_item' => __( 'Update FAQ Category', 'text_domain' ),
- 'view_item' => __( 'View FAQ Category', 'text_domain' ),
- 'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
- 'add_or_remove_items' => __( 'Add or remove FAQ Categories', 'text_domain' ),
- 'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
- 'popular_items' => __( 'Popular FAQ Category', 'text_domain' ),
- 'search_items' => __( 'SearchF AQ Category', 'text_domain' ),
- 'not_found' => __( 'FAQ Category Not Found', 'text_domain' ),
- 'no_terms' => __( 'No items', 'text_domain' ),
- 'items_list' => __( 'FAQ Category list', 'text_domain' ),
- 'items_list_navigation' => __( 'FAQ Category list navigation', 'text_domain' ),
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => true,
- 'public' => true,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'show_in_nav_menus' => true,
- 'show_tagcloud' => true,
- );
- register_taxonomy( 'faq_cat', array( 'faqs' ), $args );
- }
- add_action( 'init', 'faq_taxonomy', 0 );
- }
- // FAQS Filters
- function filter_faqs() {
- $termIds = array('1821','1820');
- $ajaxposts = new WP_Query([
- 'post_type' => 'faqs',
- 'posts_per_page' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'desc',
- 'tax_query' => [
- [
- 'taxonomy' => 'faq_cat',
- 'field' => 'term_id',
- 'terms' => $termIds,
- 'operator' => 'IN'
- ],
- ]
- ]);
- $response = '';
- if($ajaxposts->have_posts()) {
- while($ajaxposts->have_posts()) : $ajaxposts->the_post();
- $response .= get_template_part('templates/faq-single');
- endwhile;
- } else {
- $response = 'empty';
- }
- echo $response;
- exit;
- }
- add_action('wp_ajax_filter_faqs', 'filter_faqs');
- add_action('wp_ajax_nopriv_filter_faqs', 'filter_faqs');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement