Hi,
I was able to add custom post types to the search results by adding a code to the themes function.php
function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'page', 'at_biz_dir', 'mdb_item', 'mdb_person', 'mdb_series', 'mdb_company' ) );
}
}
}
add_action('pre_get_posts','search_filter');
This works fine and the desired results are displayed on the search results page.
Unfortunately they don’t appear in the live search results, when typing the term into the search field.
How can I add the custom post types to the live search results?
UPDATE: I see that the live results are using the ‘td_module_mx2’ template. Is it possible to overwrite it with a custom template, which I can store in the child theme directory?
UPDATE: I’ve managed to solve the problem, by registering my CPT in the functions.php. Now the custom posts appear in the live results.
However, these custom post types are using attached thumbnails from external directories. They don’t show up in the result (which is not a surprise).
I see that the live results are using the ‘td_module_mx2’ template. Is it possible to overwrite it with a custom template, which I can store in the child theme directory? In this case I could use my own get image functions…
Hello !
Yes, you can use this in Child Theme. Please make sure you follow our tutorial closely so you can set up your child theme properly: https://forum.tagdiv.com/the-child-theme-support-tutorial/
Thank you !
Hello !
The main td_module is this file right here: https://prnt.sc/quxvrw
I hope this was helpful !
Thank you !
I have the same problem but with custom field inclusion in live search results.
How to manipulate query of this widget?
Hi creativit,
If you are using our Newspaper theme then you can you 2 types of live search, the one from the tagDiv Cloud Library that can be edited with tagDiv Composer, for this the files responsive for the live search is this one wp-content/plugins/td-cloud-library/shortcodes/header/tdb_header_search.php
Now if you are using a standard header and not a cloud then, the live search will be on a different path, each standard header has a different path for example -> https://i.imgur.com/sJZQZI8.png now the code will be executed in javascript on this file -> wp-content/themes/Newspaper/includes/js/tagdiv-theme.js -> https://i.imgur.com/uq8v79k.png
I hope this will help you!
Thank you!