WP API and Proxy

Using a proxy is important when you cannot store your authentication credentials securely. One encounters this problem when building single page applications with client-side JavaScript Frameworks like Angular or Ember. This blog entry by Alex Bilbie nicely summarises the issue. As a side project, involving a Angular/Ionic/Cordova application and WordPress, I’m building a proxy plugin … Read more

WP REST API – get custom taxonomies based on terms & filter

Herewith find the below answer for my own question for the custom taxonomies based listing the categories add_action( ‘init’, ‘rest_custom_category_request’, 25); function rest_property_type_category_request(){ global $wp_taxonomies; $wp_taxonomies[‘custom_category’]->show_in_rest = true; $wp_taxonomies[‘custom_category’]->rest_base=”custom_category”; $wp_taxonomies[‘custom_category’]->rest_controller_class=”WP_REST_Terms_Controller”; } Answer for the filter with custom meta key & values add_filter(‘rest_query_vars’, ‘custom_rest_query_vars’); function custom_rest_query_vars($query_vars) { //print_r($query_vars);exit; $query_vars = array_merge( $query_vars, array(‘meta_key’, ‘meta_value’, ‘meta_compare’) ); … Read more

Media gallery images url instead of ID on WP API Response

This is the correct way to achieve it is this: function show_main_image($object, $field_name, $request){ $custom_fields = get_post_custom($object[‘id’]); $main_image = $custom_fields[‘main_image’]; $arregloimg = explode(‘,’,$main_image[0]); $image_urls = array(); foreach ( $arregloimg as $key => $value ) { $image_urls[] = wp_get_attachment_url($value,’thumbnail’); }; return $image_urls; }

Get a remote post ID via API given URL

The Posts endpoint accepts a slug parameter when querying for posts, so if you can get the slug from the URL, then you can make request to /wp-json/wp/v2/posts?slug=<slug>. So if the URL is http://example.com/hello-world/ and you know the slug is hello-world, then for example in JavaScript, you can do something like: fetch( ‘http://example.com/wp-json/wp/v2/posts?slug=hello-world’ ) .then( … Read more

How can I list all installed plugins/themes/versions from CLI/API?

Using WP CLI, you can record WordPress version using: wp core version –extra –path=”$SITEPATH” > wp-report.txt and append a list of plugins (with status and version): wp plugin list –path=”$SITEPATH” >> wp-report.txt and append a list of themes (with status and version) using: wp theme list –path=”$SITEPATH” >> wp-report.txt Further reading: https://developer.wordpress.org/cli/commands/core/version/ https://developer.wordpress.org/cli/commands/plugin/list/ https://developer.wordpress.org/cli/commands/theme/list/

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