Connect with us

[Coding Tutorial] Include custom post types in the WordPress Search Results

coding

[Coding Tutorial] Include custom post types in the WordPress Search Results

[Coding Tutorial] Include custom post types in the WordPress Search Results

I will start today a series of posts that will teach you some insider secrets about WordPress. I hope you will enjoy it. Any suggestions about future post topics are welcome!


 

Below is a must do code for anyone working with custom post types in WordPress. It includes those custom post types in the search results of WordPress.

// MAKE CUSTOM POST TYPES SEARCHABLE
function searchAll( $query ) {
 if ( $query->is_search ) { $query->set( 'post_type', array( 'site', 'plugin', 'theme', 'person' )); } 
 return $query;
}
add_filter( 'the_search_query', 'searchAll' );

Now, the code bellow, will also add your custom post types to your sites main RSS feed

// ADD CUSTOM POST TYPES TO THE DEFAULT RSS FEED
function custom_feed_request( $vars ) {
 if (isset($vars['feed']) && !isset($vars['post_type']))
  $vars['post_type'] = array( 'post', 'site', 'plugin', 'theme', 'person' );
 return $vars;
}
add_filter( 'request', 'custom_feed_request' );
No votes yet.
Please wait...
READ  How to Add Color Picker to WordPress Theme/Plugin/Option Panel
Continue Reading

We are a WordPress plugin developer company that focuses on useful WordPress plugin creation and empowering people to earn passive incomes from their blogs. We build unique and groundbreaking plugins that will revolutionize your blog!

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in coding

Sign up for our newsletter and get a free affiliate e-book!


About Me:

Szabi Kisded

Hi, my name is Szabi and I'm documenting my journey selling plugins on CodeCanyon. I will show you every step of it: learning to code, plugin ideas, WordPress stuff and more. Read more…

Mega Plugin Bundle:

CodeCanyon Portfolio:

Learn to Code Plugins:

Latest Promotions:

Recommended Theme:

Start Your Own Blog:

Recommended VPN Service:

Translate Your Blog:

AdSense Alternative:

Best Article Spinner:

Popular Posts:

Latest Posts:

To Top

Privacy Preference Center

      Necessary

      Advertising

      Analytics

      Other