Fetch CSS of posts

It is very unlikely that you will be able to duplicate a look of a wordpress page just by applying the CSS directly to the content as the CSS usually depends on the structure of the HTML containing the content and not only on the content itself. But fetching the CSS by itself is easy, … Read more

WP JSON API meta_query not working

Per the comment from @ialocin I switched from WP JSON API to WP REST API. There is much less documentation with the rest api but it’s customizable using native wordpress functions. Also, it has a nifty github plugin for allowing use with ACF custom fiends. Anyway, the documentatino for customization the wp rest api is … Read more

wp json api – get posts by category

I solved the problem in a different way. First I extracted all the posts by including category name inside of it. Check the answer below. public function module_data() { global $json_api; $url = parse_url($_SERVER[‘REQUEST_URI’]); $defaults = array( ‘ignore_sticky_posts’ => true, ‘posts_per_page’ => -1, ‘order_by’ => ‘date’, ‘order’ => ‘ASC’ ); $query = wp_parse_args($url[‘query’]); unset($query[‘json’]); unset($query[‘post_status’]); … Read more

How to create WordPress custom end point with multiple parameters?

When you register a route, parameters accepted via the query string (eg. ?a=b&c=d) are not registered as part of the endpoint, like you have done. Those parameters just need to be defined in the args property: add_action( ‘rest_api_init’, function() { register_rest_route( ‘woo/v2’, ‘woocommerce/order_summary_by_date’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘woocommerce_orders_by_dates’ ‘args’ => array( ‘start_date’ => … Read more

JSON API not showing full content

You can try this to show the full post content only in the JSON API: function remove_more_wpse_96740($content) { if(get_query_var(‘json’)){ global $post; $content = preg_replace(‘/<!–more(.*?)?–>/’,”,$post->post_content); } return $content; } add_filter(‘the_content’, ‘remove_more_wpse_96740’,1); by targeting the json query variable and remove the <!–more–> part of the post. If you have a custom string like <!–more But wait, there’s … Read more

WordPress JSON API restrict to specific domain

More reliable will be allowing specific IP instead of domain using REMOTE_ADDR header. You can use HTTP_REFERRER header but it is not reliable. You can do it via using rest_authentication_errors filter. add_filter( ‘rest_authentication_errors’, ‘wpse150207_filter_incoming_connections’ ); function wpse150207_filter_incoming_connections( $errors ){ $allowed_ips = array( ‘127.0.0.1’ ); $request_server = $_SERVER[‘REMOTE_ADDR’]; if( ! in_array( $request_server, $allowed_ips ) ) return … Read more

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