The public query variable in the URL is the key after the question mark (query string). On the settings → permalinks management page, if pretty permalinks is not activated, you can see it. The following URL is an example. Example Com\/? Author_name=carlodaniele author_name is a public query var used to notify WordPress that users are browsing all posts of carlodaniele users. You can add multiple public query variables to the query string, as shown in the following URL: The
Example Com\/? Author_name=carlodaniele&tag=toolbar WordPress will now specify carlodaniele and toolbar tags for all carlodaniele posts. Then we can do more. The following query string is a combination of a custom post type and a taxonomy name = taxonomy term pair. Example Com\/? Unlike post_type=food&food-family=greens public variables, non-public query variables are only available in scripts. For these reasons, you will not explore them in this post (more information can be read in WordPress Codex). Here I will briefly point out that the following URL does not provide the expected results. The
Example Com\/? In author\u in=2,4,6, author\u in is a special query variable, and word press does not display the posts of the specified author. In most cases, public query variables do not require code to manage user requests. As long as you create the correct query string, the rest will be handled by WordPress itself. Now, look at the list of exposed variables below. Load the summary eb34d6c85bbf95f31839f7a98c1d0951 type, author, category, label, category, year, month, day, etc. you can search for posts. Almost all types of queries have query variables. However, the disadvantage here is that you can create queries (called meta queries) based on custom fields. In fact, word press provides meta\u key and meta\u value to query vars, but it belongs to the private group of variables and cannot be used for URL requests. It can only be used in scripts. So how do I request a meta query from a URL query string? The
The first step is to register a new query variable. Once custom query variables are registered, they can occur in the query string like other public query variables. The following features describe how to add them to the list: Load points the b34dfcdb0300b70a8efa450a49c1347query_vars filter allows you to add, remove, or edit existing variables before executing a query. We have added two custom variables here. From now on, thanks to the get\u query\u var() function, you can get the value. The load summary 31e1b1c5e3d55bfbfbfb5bf8ef56c8a2a can now create a custom query using the query VaR value. The
A sentence of wp_query class If a user requests a specific resource (such as a single page, search results, or post list), WordPress will use a method to instantiate a new wp\u query object, which allows the user to manipulate the actual SQL query before running. Suppose you are familiar with the wp_query class. Otherwise, please check the wp_query Conquest’s in-depth guide before reading this post. When creating a custom field (meta) query, there are many parameters that can be used to set a custom field query, such as the multi-dimensional array meta_query parameter that uses a single meta query keyword. The
Key (string) – SA
User defined field key value (string|array) – user defined field value type (string) – user defined field type comparison (string) – set the comparison operator, such as the meta|u query parameter: Load summary 9e23a51816cc03eba9db89d4a4ee8add \
Athinfo persistent links (index.php appears in the URL) by default, word press uses an ugly persistent link structure. (for example: http:\/\/example.com\/?post_type=book perhaps http:\/\/example.com\/?p=123 ) But we know how important a beautiful permanent link structure is (for example: http:\/\/example.com\/book\/harry-potter-and-the-chamber-of-secrets\/ ) Therefore, go to the installed Settings > permanent link management page. Set up the desired structure. You can determine one of the available options or set up a custom structure to provide one or more structure labels. These tags are keywords that can be added to permanent links to give specific meaning. For example,%year% tells the user the year the post was posted. WordPress provides 10 default structure tags, but you can add any number of custom tags for each custom query variable that you previously registered. When the structure is activated, the release year will be displayed before the post name. That is, our last job is to register the custom structure tag and instruct WordPress how to use it. With the rewrite flag added, let’s connect the following functions to the init task. Load summary 4c4ea491486ebaca8d9502b847549758add ABCD rewrite ABCD tag function registers a new structure tag. This function retains three arguments: the tag name, the regular expression that matches the tag name, and an optional query (not set here). WordPress now recognizes tags. Just register a rewrite rule that will tell WordPress how to use it. The codes are as follows: Load summary f364d707472739bdf61b9ad7f0d61707add\u rewrite\u rule() function will perform magic here: the first parameter is the regular expression matching the request URL. The second argument is the URL to import when the regular expression matches. The last argument is a string, and the value can be \