Using WP_Query to grab custom meta values, foreach to json object

The best way to go about this is with $wpdb. The query to draw out meta_value by category is: $query = $wpdb->get_results( “SELECT p.`ID`, pm.`meta_value` FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} `p` ON `p`.`ID` = pm.`post_id` LEFT JOIN {$wpdb->term_relationships} `tr` ON `p`.`ID` = `tr`.`object_id` LEFT JOIN {$wpdb->term_taxonomy} `tt` ON `tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id` WHERE `pm`.`meta_key` = … Read more

Custom url in wordpress

You just need to have a handler function that is called before content is sent to the browser. Without knowing exactly what you are trying to do, here is a general function that will work: function my_plugin_json_handler(){ /*First you should check the POST/GET Request for some variable that tells the plugin that this is a … Read more

How to disable WordPress blog folder

To clarify, /blog and /blog/ are the same. The slash is added by the browser to properly structure the URL (best way I can explain it). Your’re trying to access two different pages with the /blog/ slug. In this case, WordPress is overriding the blog link from your existing website and showing content from there. … Read more

body_class REST field in WP-API

get_body_class() relies on $wp_query to do its thing, which is apparently a no-go for the JSON API. I considered creating a global object to hold the body class, and just using that to keep the body_class up to date…but that wouldn’t work without page reloads, and there would be no assurance that the object was … Read more

Input data from email form not going to JSON file

I have checked the code. file_put_contents function accepts the absolute path for the file. Use the ‘get_template_directory()’ function for the absolute path. Please check the updated code. <form method=”get”><p id=”myform”><input type=”email” name=”EMAIL” placeholder=”enter email address” required /> <input id=”submit” name=”submit” type=”submit” value=”Sign up” /></p></form> if (isset($_POST[‘submit’])) { $file = get_template_directory() . ‘/data.json’; $json_string = json_encode($_POST, … Read more