2

I have a custom post type tickets. Here I have some categories. And here is my codes.

     register_post_type( 
                    'tickets', 
                    array( 'labels' => array( 
                            'name' => __( 'Help and Support' ), 
                            'singular_name' => __( 'Help and Support' ) ), 
                        'public' => true, 
                        'has_archive' => true, 
                        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ))
                    );

// register the new ticket category
register_taxonomy( 'ticketcat',
        array( 'tickets'),
        array('hierarchical' => true,                    
                'labels' => array(
                        'name' => __( 'Categories', 'test'),
                        'singular_name' => __( 'Categories', 'test'),
                        'search_items' =>  __( 'Search Categories', 'test'),
                        'all_items' => __( 'All Categories', 'test'),
                        'parent_item' => __( 'Parent Category', 'test'),
                        'parent_item_colon' => __( 'Parent Category:', 'test'),
                        'edit_item' => __( 'Edit Categories', 'test'),
                        'update_item' => __( 'Update Category', 'test'),
                        'add_new_item' => __( 'Add New Category', 'test'),
                        'new_item_name' => __( 'New Category', 'test')
                ),
                'show_ui' => true,
                'query_var' => true,
                'update_count_callback' => '_update_post_term_count',
                'rewrite' => array( 'slug' => 'qualification', 'hierarchical' => true ),
        )
); 

Now, the Custom post type is working in back-end, I can add, edit delete any post. But when I search a post, its showing empty results. I have looked following questions already. But none helped me the query working.

first Wordpress Stack again

and few more quesions as well. But not working. From those question I tried to check the url of the search results page. Here is it.

edit.php?s=technical&post_status=all&post_type=tickets&action=-1&m=0&paged=1&mode=list&action2=-1

and here is the screenshot for reference. enter image description here

1 Answer 1

1

For the Post table Search option, It will check with post titles. Not the whole table like what you can do it on jQuery DataTable. So, this options is not supported in default. But I found some code for you to work on, I didn't try the code, check it on your own risk.

function cf_search_join( $join ) {
    global $wpdb;

    if ( is_search() ) {    
        $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
    }

    return $join;
}
add_filter('posts_join', 'cf_search_join' );

function cf_search_where( $where ) {
  global $pagenow, $wpdb;

   if ( is_search() ) {
      $where = preg_replace(
        "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
        "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
    }

   return $where;
   }
 add_filter( 'posts_where', 'cf_search_where' );


 function cf_search_distinct( $where ) {
   global $wpdb;

    if ( is_search() ) {
        return "DISTINCT";
   }

   return $where;
 }
 add_filter( 'posts_distinct', 'cf_search_distinct' );

try and if you have any problem check here. for more details. Here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.