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

Lionel POINTET lionel.pointet at globalis-ms.com
Mon Apr 23 08:26:53 UTC 2012


Hi Becky,

When WordPress knows what kind of query is currently going, the template is
guessed, then called with a filter named 'template_redirect'.
You can hook on that filter to make sure it's your template that will be
included.
But make sure you don't break any other query than yours by making this,
like a normal archive or author query...

Hope that helps.
Lionel

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
>
>
>
> ______________________________**_________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>


More information about the wp-hackers mailing list