I have added a new custom post type named: website_bookmarks
I plan on using it as my bookmarks manager (going to export all my bookmarks from Google Chrome into my custom post type) for the following reasons
- Can search bookmarks easily
- Can add tags (php, web design, etc...)
- Can add descriptions to explain the bookmark better
- Can view and sort however I choose
- Can access from anywhere online
- Can share my bookmarks with my readers ( will have option to mark a bookmark as Private or Public so I can be the only one to view the Private ones)
- Sure there are other reasons to make this a good idea
Now my only problem so far is the search part. I cannot get my wordpress (latest release) to search the website_bookmarks post type for anything.
I have modified my search form with a hidden field
<input type="hidden" name="post_type" value="website_bookmarks" />
So on my search page in the URI I will see...
www.mydomain.com/?s=mysearchterm&post_type=website_bookmarks
The problem is it ONLY shows search results for my regular blog post and no results from my custom post type.
If I remove the s=mysearchterm
from the URI so it is now
www.mydomain.com/?post_type=website_bookmarks
then it will show ALL the post from my custom post type. This shows that the website_bookmarks is the proper name for my post type, just the search part is not working correctly. It will retunr search results from regular post with no problem, just none from my website_bookmarks post type
It should not be showing any results for my blog post and ONLY results for my custom post type website_bookmarks
Can someone help me? I can not figure out why it will not work, the code I show above for modifying the search form, I found online from others saying that it worked for there blogs simply by changing the search form to what I did above.
Below is my whole search.php file as well
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<h1 class="pagetitle"><?php printf( __("Search results for <span>%s</span>", "vigilance"), get_search_query()); ?></h1>
<img class="archive-comment"src="<?php echo get_template_directory_uri(); ?>/images/comments-bubble-archive.gif" width="17" height="14" alt="Comments"/>
<div class="entries">
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php esc_attr( sprintf( __( 'Permanent Link to %s', 'vigilance' ), the_title_attribute( 'echo=false' ) ) ); ?>"><span class="comments_number"><?php comments_number( '0', '1', '%', '' ); ?></span><span class="archdate"><?php the_time( __( 'M.j.y', 'vigilance' )); ?></span><?php the_title(); ?></a></li>
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>
</ul>
</div><!--end entries-->
<div class="navigation">
<div class="alignleft"><?php next_posts_link( __( '« Older Entries', 'vigilance' )); ?></div>
<div class="alignright"><?php previous_posts_link( __( 'Newer Entries »', 'vigilance' )); ?></div>
</div><!--end navigation-->
<?php else : ?>
<h1 class="pagetitle"><?php printf( __("Search results for '%s'", "vigilance"), get_search_query()); ?></h1>
<div class="entry">
<p><?php printf( __( 'Sorry your search for "%s" did not turn up any results. Please try again.', 'vigilance' ), get_search_query());?></p>
<?php get_search_form(); ?>
</div><!--end entry-->
<?php endif; ?>
</div><!--end content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I have even tried using this code below in my functions.php file with no luck...
function mySearchFilter($query) {
$post_type = $_GET['post_type'];
if (!$post_type) {
$post_type = 'any';
}
if ($query->is_search) {
$query->set('post_type', $post_type);
};
return $query;
};
add_filter('pre_get_posts','mySearchFilter');
Below is my code used to create the website_bookmarks post type, you can see that I have enabled query_var and publicly_queryable and have set exclude_from_search to true and false to test it both ways, with no luck
$bookmark_args = array(
'labels' => $bookmark_labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'bookmark',
'with_front' => false),
'taxonomies' => array('bookmark_tags'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 4,
'can_export' => true,
'supports' => array(
'thumbnail', //website thumbnail
'excerpt', //website description
'title', //website title
'custom-fields',
'comments'
)
);
register_post_type('website_bookmarks', $bookmark_args);