How to use get request in page template (wordpress) - php

How can I use the get method in WordPress?
I'm using a page template and I want to get.
When I use the get method in wordpress it redirects me to the URL without the ?page=1.
Please note that post method is working correctly.

You should be able to use get in wordpress. It sounds like you might have a server misconfig. Checkout this SO question for information on how to make sure apache is configured correctly.

Related

How can I rename the WordPress AJAX URL?

I'm currently looking for a way to change / hide the default WordPress admin-ajax.php URL. I want to do this to remove the admin from it to prevent misunderstandings by my customers when I use the AJAX URL to read for example a file from my server. In this case, the URL has the admin prefix which is a bit confusing.
So in result the AJAX URl should looks like this: ajax.php
I've searched a bit but I can't find any helpful information. Because of this I can't show you any related code. But when I got it, I'll update my question to help other people.
Alternatively and perhaps more effectively you could leverage WP API and create a custom endpoint to process your data so that there isn't url confusion.

Show a custom URL in the header on a WordPress post

I am trying to achieve a customized url that shows in url header. Different for every WordPress post.
For example, I have posts in WordPress about different countries what I want is that when I click on a country the single post page which normally shows up like this in the browser url field:
www.example.com/2017/11/china
Should show up like this, only in header like.
china.example.com or
russia.example.com
I don't know if I can achieve this using WordPress or Do I have to play around with .htaccess file.
There are more than 200 posts and I am trying to find a way to do it using an automated script or WordPress code.
I want this link to be associated with the actual post on the WordPress site. Please let me know if it's achievable or if there is already a post on stack overflow that solves this. I couldn't find one. Thank you.
china.example.com is a subdomain, example.com/.../china is a folder. They are actually two different things. To achieve this effect though, you would need to set up a multi-site wordpress installation, and treat china.example.com as one website and russia.example.com as another

How to create a custom url on wordpress site to be called from an external server?

I am developing a plug-in for wordpress, and I need to expose an url to be called from a remote server that will send me 3 get variables.
my url(s) should be like this:
http://www.example.com/api/videos/callback/?variable1=value1&variable2=value2&variable3=value3
where example.com is my website.
And when I receive the call I want to get this variables and something.
I have to receive 3 calls the first with 2 of this variables and seconde with 3 variables and the third one with 1 variable.
All of these calls will be the answer of my request sent with curl(but I think it doesn't matter).
I tried rewrite rules and add_endpoint but I didn't figure where and how to use it and if i need some additional plugin to do so.
Thank you for your help!
Use wp_remote_get() .
See the Wordpress Codex for more info about this function.
You can install wordpress plugin json api for this
https://wordpress.org/plugins/json-api/
Also please go through installation notes
https://wordpress.org/plugins/json-api/other_notes/
in case anyone want to know the answer, i simply used
add_rewrite_rule('^api/videos/callback$', 'index.php', 'top');
flush_rewrite_rules(true);
and for the variables i didn't make any thing, to access them i used $_GET and making all checks is exists i then execute my code.

Generate link to clone or duplicate a post from wordpress frontend

I've found a number of plugins for wordpress that add a link to the table in the backend to clone or duplicate a post or page (Duplicate Post, Clone Post, and Post Duplicator). This is nice, but I'm building a bit of an app on wordpress where I'm using a custom post type as an entry and would like to be able to quickly copy an entry with a link from the frontend of the site (similar to how edit_post_link works but without jumping into the backend).
I'm using Gravity Forms for the create and edit functionality for entries on the frontend, but I can't quite figure out the best approach for a secure way to submit a request, execute the clone query, and the return to the same page I was on before (i.e. not jumping into the backend). Gravity Forms Post Updates plugin does something similar with a do_action call to generate a link. I've looked through this function and generally get what's happening, but I'm not sure if I need all of the extra plugin class structure.
I was hoping to find an example of a function that could create a secure url with a nonce and then another function we validate the url and execute the query and return to the previous page. Is this the right way to go or am I barking up the wrong tree? If so, any code samples or examples that might be able to help get me started?
Much appreciated!
I found this post (http://rudrastyh.com/wordpress/duplicate-post.html) and was able to figure out what I needed to. Instead of adding a filter to include the link in the backend, I instead created an action that can be called with do_action and generates the link. I also have a page and page template that is solely for executing the call and then redirecting back to the referring url.

WordPress Plugin populating a Page with custom URL parameters

OK, I'm writing a WordPress plugin with a dedicated DB table. I want to display a given record using a WP page. I want to simply include a short code in the page that calls a function to get the url parameters and generate the content. Simple so far. The problem I'm having is I can't find a way use mo_rewrite with WP to have URLS like this:
http://site.com/page/mydbrecordid
I also want http://site.com/page/ to activate the same function obviously with some default output.
I can't find a similar use case documented anywhere.
Thanks!
Perhaps instead of using mod_rewrite to transform your friendly URLs into parameterized ones, you could simply hook the 'template_redirect' action, then render whatever you want according to the path in $_SERVER['REQUEST_URI'] and any other URL parameters.
One thing you could do in the action function is to pull page content from the DB, evaluate it using do_shortcode() and apply the usual filters (wpautop, convertchars, wptexturize). That way, you can register your own shortcodes to pull data from your custom table and use them in any page/post/widget, including pages you render from the template_redirect action hook.
Without knowing all the details of your use-case, it is difficult to know if this is the best option or not.

Categories