How to Rewrite WordPress URL for a Plugin

Create an endpoint. In the callback function for the endpoint call your plugin functions internally, so the whole WordPress environment is available and you are still on the same domain, no matter where the plugin URL is. Plus, make sure not to flush the rewrite rules on every page load, use the (de)activation hook for … Read more

How to Rewrite WordPress URL for a Plugin

Create an endpoint. In the callback function for the endpoint call your plugin functions internally, so the whole WordPress environment is available and you are still on the same domain, no matter where the plugin URL is. Plus, make sure not to flush the rewrite rules on every page load, use the (de)activation hook for … Read more

variable endpoints for webservice

Ok, so it might have been working all along, and I just hadn’t flushed the rewrites! function my_dept_listing_init() { //Easy flush if (isset($_GET[‘flush’])) { flush_rewrite_rules(); } //endpoint onto which queries are made add_rewrite_endpoint( ‘individuals’, EP_PAGES ); //This filter acts as a controller, inject into content add_filter(‘the_content’, ‘my_dept_listing_content_ctrl’); } add_action(‘init’, ‘my_dept_listing_init’); function my_dept_listing_content_ctrl($content) { global $post; … Read more

How to use endpoint, but remove/rewrite endpoint base?

I think the add_rewrite_rule is the correct route to go and I think what you have is correct also barring the Regex. Try substituting what you have currently for this => ^my-page\/([0-9]+)\/?. Full code below: function setup_filter_rewrites(){ add_rewrite_rule(‘^my-page\/([0-9]+)\/?’, ‘index.php?pagename=my-page&my_var=$matches[1]’, ‘top’); } add_action( ‘init’, ‘setup_filter_rewrites’ );

How to get custom or filtered endpoints in WordPress API?

Here is an example of how to use Javascript to read posts from the WordPress API. //Pegasus = Theme name $.getJSON(‘https://visionquestdevelopment.com/wp-json/wp/v2/posts’, function(data){ //foreach post for (i = 0; i < data.length; i++) { //console.log(data[i]); var output=””; var dateT; var dateArr = []; //skip one of the posts with 404s on images if( ‘1555’== data[i].id ) … Read more

Get The latest post from a category

First of all, you registered the route “latest-post”, but the URL you used is “latest-posts”. Second: In your “get_latest_post” function, you use the variable $category, but it is set nowhere. Fix the function like this: function get_latest_post ( $params ){ if(isset($params[‘category’])){ $post = get_posts( array( ‘category’ => $params[‘category’], ‘posts_per_page’ => 1, ‘offset’ => 0 ) … Read more