I have a structure like this for my custom post types: domain.com/member/member-name/book/book-name Basically, I have a custom post type of member, and the member-name is the post. What I want to do is pass a variable called books, but I can't get my code to work. I've based my solution on one that has previously been asked on here but my structure is different, and I've googled and googled to no avail. I really cant get my head around rewrite …
Plugin in question: http://dimsemenov.com/plugins/royal-slider/wordpress/ Background: This is a great plugin, and it features a 'post' version where the slider pulls content from posts. However, the taxonomy for the posts that it's pulling has to be set at the slider settings level in WordPress, it can't be done via shortcode (that we know of). The plugin author does offer a way to override the default query here: http://help.dimsemenov.com/kb/wordpress-royalslider-advanced/wp-modifying-order-of-posts-in-slider Aim: create a custom shortcode through which we can pass custom attributes, and …
I want to rewrite mysite.com/events/submission/test-event-01 to mysite.com/events/submission?epl=test-event-01 This is what I have done so far without any result. I get a 404 error (mysite.com/events/submission/test-event-01). Can anyone suggest the correct rule? add_action( 'init', 'epl_rewrite'); add_filter( 'query_vars', 'epl_query_vars'); function epl_rewrite() { add_rewrite_rule('^submission/([^/]*)[/]?', 'index.php?pagename=submission&epl=$matches[1]', 'top'); } function epl_query_vars( $query_vars ) { $query_vars[] = 'epl'; return $query_vars; } Note: Permalinks are re-saved to flush the rewrite rules. mysite.com/events/submission page is already added. Thank you in advance.
I've been messing around with rewrites and query_var to generate some listings, for example: ~/my-page/?my_var=1 ~/my-page/?my_var=2 ~/my-page/?my_var=3 After perusing StackExchange and the interwebs a bit, it seems that the overwhelming consensus is that add_rewrite_endpoint is the way to go. As such, I've implemented the following: function wpd_add_my_endpoint(){ add_rewrite_endpoint( 'my_var', EP_PAGES ); } add_action( 'init', 'wpd_add_my_endpoint' ); This yields the following URIs based on the ones I mentioned previously: ~/my-page/my_var/1 ~/my-page/my_var/2 ~/my-page/my_var/3 However, I would like to strip out the 'endpoint …
I would like to load the same page under a different URL, but not via a redirect. For example, suppose I create some page with id=6 - I can access this page via example.com/index.php?page_id=6 - if Im using pretty permalinks, I can give this page a path like /mypage and it will also be accessible at example.com/mypage. But what if I want to access this page at example.com/alsomypage? In other words, both example.com/mypage and example.com/alsomypage will load the content given …
I would like to rewrite a path like example.com/foo to the "front" page (example.com). So when I request example.com/foo the content shown should be that of example.com. Note, a redirect is NOT what I am looking for here. I am trying to do this with the add_rewrite_rule() function but cant find the query vars to get the homepage add_action( 'init', function() { add_rewrite_rule( '^foo/?$', 'index.php?pagename=homepage', 'top' ); }); I also tried index.php?pagename=/, index.php?page=front, index.php (no query vars) and a bunch …
Essentially I'm trying to allow a URL like this: https://example.com/products/my-product/test I'm using WooCommerce, my product base is /products, and the product name would be My Product here. I want to allow the URL segment /test and then detect that and redirect to a custom template. I'm almost there, but I can't get the template_include filter to properly use the custom template. add_filter( 'query_vars', function ( $vars ) { $vars[] = 'test'; return $vars; } ); add_action( 'init', function () { …
I have an issue with passing an array of strings to a SQL statement in a WordPress plugin, because the prepare method adds a backslash before each apostrophe. // I have an array of strings. $the_array = ['red', 'green', 'blue']; // I convert the array into a single string containing comma separated values surrounded by apostrophes. $the_string = "'" . implode("', '", $the_array) . "'"; // And I pass the string to the query, using prepare (necessary to avoid SQL …
I don't want my custom post type to be loaded by using query string at ?{query_var}={post_slug}. So I have set the argument below in my custom post type: 'query_var' => false, But this gives me a 404 page when I load my custom post type page using clean URL, for examples: /news/news-sample-1/ /news/news-sample-2/ /news/news-sample-3/ Why? What have I set wrong? Below is my custom post type declaration: function news_init() { $args = array( 'labels' => array( 'name' => __('News (Pages)'), …
I have the following I'm trying to enqueue in functions.php wp_enqueue_script( 'param-example', 'https://domain.com/example?f=j&s=w&c=t', array(), null ); Except WordPress is escaping the ampersands in the HTML which is breaking the script. How can I prevent WordPress from escaping the URL in wp_enqueue_script? The other examples that seem close to this question haven't worked.
I have been stuck on this for hours and tried all these different methods but none seem to work. I've seen other threads with a similar problem but the solutions are not working for me. I'm hoping someone can help. I have a page with a custom template using the permalink example.com/central This page accepts query variables eg : example.com/central/?information=people I'm trying to get a custom rewrite rule to work so that when people type in example.com/central/information/people it will display …
I am trying to make query_vars work in rest api. In my code bellow if I call wp-json/wp/v2/cpt?city=test, my debug output always returns an empty string. <?php /** * Plugin Name: Test * Author: Gecka <[email protected]> * License: GNU General Public License v3 or later * License URI: http://www.gnu.org/licenses/gpl-3.0.html */ function cpt_init() { $args = [ 'label' => 'Custom post', 'supports' => [ 'title', 'revisions', 'custom-fields' ], 'show_in_rest' => true, 'hierachical' => false, 'public' => true, 'exclude_from_search' => true, 'show_ui' …
I have a custom post type "press-release" that I pass a query var to the template through the URL. The URL structure looks like this. MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/?client=123 When I go to the url everything works as expected. I am able to grab the value from the query var. The issue I have is on page load Wordpress then rewrites the URL to be: MYDOMAIN.COM/press-release/TITLE-OF-RELEASE/ I need to keep the query var in the URL structure so people can share the URL. …
I have a loop and in that loop I use a get_template_part to call the HTMl for the post to display. I also have a variable (number) to which +1 is added every time the loop runs. In this way I can track which post is displayed (for a specific layout). <?php $loop_post_count++ ?> <!-- HTML code for loop --> <?php get_template_part ( 'loop') ?> This all works fine, but now I want to have an if-condition in the loop.php …
I would like to create an endpoint for a custom field. For example, I already have a custom 'competition' post type for which rewriting is working great and resolving at website.com/competitions/my-competition. Within that competition I have award categories created using Advanced Custom Fields, all of which have a unique ID. I would like to be able to visit website.com/competitions/competition_slug/award-category/category_slug. I've got as far as passing the unique ID of the category to the query vars and loading a custom template …
I have this definiton to add a query var: add_filter( 'query_vars', 'add_reg_query_vars', 10, 1 ); function add_reg_query_vars($vars) { $vars[] = 'seminar'; // return $vars; } and this definition to add a rewrite rule: add_rewrite_rule( '^seminare/([a-zA-Z0-9]+?)/([^/]*)/?$', 'index.php?pagename=seminare/$matches[1]&seminar=$matches[2]', 'top' ); Like this it is working well, links like /seminare/mysite/123/ are matched, but because I have on same page 'seminare' a pagination, I need to exclude the word 'page', that a link like seminare/page/2 is not matched by my regex above. Can't get …
I need the pagination liks to have the url, like: current_url?p-page=1 current_url?p-page=2 current_url?p-page=3 And so.. The reason I need this is because I have other params in the page. the problem is that in the docs, it specs: format (string) (optional) Used for Pagination structure. The default value is '?page=%#%', If using pretty permalinks this would be '/page/%#%', where the '%#%' is replaced by the page number. Default: '?page=%#%' And I have friendly url enabled, How can I prevent the …
I have an unusual use of add_rewrite_rule (is there a usual use?) and I am getting some unexpected behavior. First here is my code: if(!empty($list_view_template)) add_rewrite_rule( "{$list_view_template}/(.*)?", 'index.php?mlscrit=$matches[1]/list-view/&pagename=' . $list_view_template, 'top' ); add_filter('init', 'mls_declare_mls_custom_vars'); function mls_declare_mls_custom_vars() { add_rewrite_tag( '%mlscrit%', '(.*)' ); } so as you can see I am using a pagename set within the admin dashboard to a variable called $list_view_template to limit a rewrite rule. This works fine so long as I flush rewrite rules after I update …
I'm adding my query arg as such: add_filter( 'query_vars', function( $qvars ) { $qvars[] = 'my_query_var'; return $qvars; }); And when I do: add_action( 'init', function() { $string = get_query_var( 'my_query_var' ); echo( $string ); }); It's not available, yet if I hook very, very late, like loop_start, it's there. What exactly am I missing? The string I passed is there if I inspect $_GET.