[wp-hackers] Issue with Custom Post Type Archive and custom search form

Becky Resler becky.absolute at gmail.com
Mon Apr 23 14:22:42 UTC 2012

I ended up figuring it out and thought I'd share in case anyone else is 
having the same issue.

I was already hooking into the "single_template" and "archive_template" 
filters to get WordPress to use my custom templates with my plugin for 
the single page and archive pages. That was working just fine.

I am now also hooking into the "template_include" filter (which is run 
after the other two) and checking if the page being displayed is for my 
custom post type AND if my custom search is being done [by checking for 
a hidden value I added to my custom search form]. If both are true, I'm 
telling WordPress to use my custom post archive template. That worked. :)

The other queries are working just fine for everything else on the site.


> 2012/4/20 Becky Resler<becky.absolute at gmail.com>
> I'm creating a plugin that sets up a job board for a client's website. I
> set up a custom post type for the job openings and a custom taxonomy for
> job opening categories.
> When I set up the custom post type, I set it to have have an archive page.
> The code for my CPT is below.
> $labels = array(
>                     'name'                  =>  _x('Job Openings', 'post
> type general name'),
>                     'singular_name'         =>  _x('Job Opening', 'post type
> singular name'),
>                     'add_new'               =>  _x('Add New', 'job_opening'),
>                     'add_new_item'          =>  __('Add New Job Opening'),
>                     'edit_item'             =>  __('Edit Job Opening'),
>                     'new_item'              =>  __('New Job Opening'),
>                     'view_item'             =>  __('View Job Opening'),
>                     'search_items'          =>  __('Search Job Openings'),
>                     'not_found'             =>  __('No job openings found'),
>                     'not_found_in_trash'    =>  __('No job openings found in
> Trash'),
>                     'parent_item_colon'     =>  __('Parent Job Opening:'),
>                     'menu_name'             =>  __('Job Openings')
>                 );
>         $args = array(
>                     'labels'                =>  $labels,
>                     'public'                =>  true,
>                     'publicly_queryable'    =>  true,
>                     'show_ui'               =>  true,
>                     'show_in_menu'          =>  true,
>                     'show_in_nav_menus'     =>  true,
>                     'query_var'             =>  true,
>                     'capability_type'       =>  'post',
>                     'hierarchical'          =>  false,
>                     'menu_position'         =>  20,
>                     'supports'              =>  array('title', 'editor',
> 'author'),
>                     'has_archive'           =>  'job-board',
>                     'can_export'            =>  true,
>                     'rewrite'               =>  array('slug' =>
> 'job-board/%post_id%', 'with_front' =>  false)
>                 );
> I have a custom template for the archive for my custom post type. On that
> template, I have added a search form to filter down the results by keyword,
> category (custom taxonomy), author, and a couple custom meta values. The
> form is posting to the archive page.
> I'm hooking into the *request* filter to add my filters to the query ...
> add_filter('request', array(&$this, 'modify_job_board_archive_**query'));
> Things are working just fine except for when I filter by category or
> author. When I filter by category, the category archive template is used
> rather than the custom post type archive template. Same thing with the
> author ... author archive template is used.
> I can't figure out where to hook into to make sure that my custom post
> type archive template is used.
> Any ideas? Or won't I be able to hook into the core WordPress
> functionality for this?
> Thanks in advance.
> Becky

More information about the wp-hackers mailing list