0

I'm creating a plugin where a file is loaded and if a link is clicked, it passes some variables that are appended to the url. So if a link is clicked it will change the url by appending filter/?term=il_Massac,st_locked which should load the filter.php file.

My issue is how do I get it to use the filter.php which is included in the plugin? The main plugin file is called meta-box.php. If I added it the the theme as a page, it works but I want the plugin to do the work instead of adding a page. Right now, if I don't use it as a page-template in the theme folder and just have it in the plugin folder, it gives a 404.

Here is the code to the link that is in my meta-box.php file: <a href="<?php echo home_url()?>/filter/?term=<?php echo $term ?>">search link</a>

$term is a variable that has some search parameters in it. So if I click that link, it gives me the 404 page rather than loading the filter.php file to execute some code. Again, I can add it the the theme as a page template but I would like it to be contained within the plugin so it does not need to be added to the theme as a page template.

Does that help?

Any suggestions on how I might do this?

2
  • 2
    Sorry man, not clear enough, at least for my understanding. Please include the relevant code. Commented Jul 29, 2013 at 15:43
  • I edited my question and please let me know if I'm still not clear enough. Thanks! Commented Jul 29, 2013 at 15:54

1 Answer 1

0

I ended up answering my own question by using the following code

add_filter( 'template_include','include_filter_template_function', 1 );

function include_filter_template_function($template_path ) {
        $template_path = plugin_dir_path( __FILE__ ) .'filter.php';

return $template_path;
}

and checking the params on that page. I'm sure there is a more elegant way to do this but it works for me. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.