Best way to make a JSON API from WordPress?

I dont know how to edit question, I found this: but this way I cannot specify my requests, is there any way to modify this code so that I can specify it? function check_api_data() { if(isset($_GET[‘api’]) ) { if ($_GET[‘api’] == ‘json’){ $args = array( ‘post_status’ => ‘publish’, ‘nopaging’ => true, ‘orderby’ => ‘title’, ‘order’ … Read more

How to create REST Based JSON API(how to modify the code below)?

try this: if (isset($_GET[‘api’])) { if ($_GET[‘api’] == ‘json’ && isset($_GET[‘id’])) { $args = array( ‘p’ => $_GET[‘id’], ‘post_type’ => ‘any’// ID of a page, post, or custom type ); $query = new WP_Query($args); // $query is the WP_Query Object $post = $query->post; // $post contains the post object header(“content-type: application/json”); echo json_encode($post); } exit(); … Read more

Why does “if statement” has to “die()”, otherwise wont work?

Most likely it’s simply because $_GET[‘first’] is not defined when you try with ?second=case&id=204. Instead, try this CODE (assuming first & second can’t appear at the same time): if (isset($_GET[‘api’])) { if (isset($_GET[‘first’]) && $_GET[‘first’] == ‘case’ && isset($_GET[‘id’])) { // $query is the WP_Query Object $post = get_post($_GET[‘id’]); // $post contains the post object … Read more

Trouble Commenting via the WP REST API using nonces

I solved it. add_filter( ‘filter_rest_allow_anonymous_comments’, ‘__return_true’ ); should be: add_filter( ‘rest_allow_anonymous_comments’, ‘__return_true’ ); I found it by looking for the filter itself and saw that it was different than in the original answer.

Upload image to wordpress using ionic/cordova with WP REST API V2

you can plain javascript file upload for this with ionic framework. const url=”YOUR_WP_ACTION_RUL”; const form = document.querySelector(‘form’); form.addEventListener(‘submit’, e => { e.preventDefault(); const files = document.querySelector(‘[type=file]’).files; const formData = new FormData(); for (let i = 0; i < files.length; i++) { let file = files[i]; formData.append(‘files[]’, file); } fetch(url, { method: ‘POST’, body: formData }).then(response … Read more

Enable identical menu on network sites

Worked it out. Assuming using a theme which has a menu location called ‘primary’, and you have just created a menu with an id contained in $menu_id $menu_locations = get_nav_menu_locations(); $new_menu_locations = array_map( ‘absint’, [‘primary’ => $menu_id]); $menu_locations = array_merge( $menu_locations, $new_menu_locations ); set_theme_mod( ‘nav_menu_locations’, $menu_locations ); This is pretty much exactly how WordPress itself … Read more

Fetching WP.me shortlinks for posts using WP Rest API

This has been resolved by registering a new field in the rest api using the following functions. add_action( ‘rest_api_init’, ‘sam_add_custom_rest_fields’ ); function sam_add_custom_rest_fields() { $sam_short_link_schema = array( ‘description’ => ‘Short Link’, ‘type’ => ‘string’, ‘context’ => array( ‘view’ ) ); register_rest_field( ‘post’, ‘samad_short_link’, array( ‘get_callback’ => ‘sam_get_short_link’, ‘update_callback’ => null, ‘schema’ => $sam_short_link_schema ) ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)