![]() ![]() ![]() Make sure to reference the pre_get_posts action API. You can update this conditional to meet your needs.We also make sure this query does not affect admin pages by adding !is_admin() to the conditional. */ function add_query_vars_filter ( $vars ) add_action ( 'pre_get_posts', 'movie_archive' ) įirst, we make sure this function will only run on the movie archive page. Open your theme's functions.php file and enter the following.In order to for WordPress to recognize these custom parameters, we need to create Custom Query Vars. Wouldn't it be nice if we could search against custom fields, related content and other data? For example, what if I wanted to search for all movies that have at least a 3 star rating? I can't just add ?rating=3 to the URL and expect it to work. For example, if you navigate to the blog page for a WordPress site and pass ?s=test into the URL, the loop will show all posts that contain test in the title or description. Since public query vars can be passed into the URL, we can alter the current loop just by appending the URL. Public query vars can be used in the URL querystring. Query vars are fed into WP_Query, WordPress' post querying API. ![]() By default, WordPress ships with several dozen Public and Private Query Vars. The ability to categorize each movie with the movie_category custom taxonomy.This tutorial is going to cover searching against a custom post type tagged with a custom taxonomy, custom fields, and relational data. Specifically, we are going to add a custom search form on the archive of a custom post type. In this tutorial we are going to create a custom search form in WordPress. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |