Tag Info

Hot answers tagged

9

serialize representation can be stored in text and reversed JSON representation can be stored in text but cannot always be precisely reversed Run this example: $query = new WP_Query(); var_dump( $query ); var_dump( unserialize( serialize( $query ) ) ); var_dump( json_decode( json_encode( $query ) ) ); After going through serialize accurate WP_Query ...


7

If you are using PHP 5.2+ you're best bet is to just make a PHP array or object and use json_encode(). UPDATED: $cats = get_categories(); $output = array('categories' => array()); foreach ($cats as $cat) { $cat_output = array( 'cat_id' => $cat->term_id, 'cat_name' => $cat->name, 'posts' => array(), ); ...


7

It did appear that the json wasn't being cached by wp-super-cache, but we decided to take a different approach. By using the transient api, we were able to do a faux-cache on all json, and drastically reduce the taxing of the database. Then on the ajax side of things, we are caching the html that is created from this semi-cached json. Things are super ...


6

WP Super Cache examines your WordPress site's pages for some HTML tags before it caches them. Your pages most probably don't have </html> tag (common issue), in that case, try adding something like //</html> -- that's a workaround, and WP Super Cache should then generate cached versions of your pages. Why does WP Super Cache do it like that? ...


6

I took a look at the WordPress app for Windows 8. It looks as though it is strictly built for WordPress.com, not self-hosted blogs. The apps available for Android, iOS, and Windows Phone on the other hand actually support both self-hosted installations and WordPress.com. Even though you integrated some WordPress.com services into your blog via JetPack, it ...


6

TL;DR Yes, WordPress can certainly act as a backend for a mobile app. Yes, a page can act as a rest endpoint / interface. No, a theme template is not the right territory for the logic. Write your own plugin. Pointers I find it hard to believe that no one else has done this. I, for one, have. More than once. And I'm near certain I'm not alone. "No ...


6

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to get one: https://developers.google.com/webfonts/docs/developer_api It's ...


5

My idea was to schedule this function, so it will run once every day or so. After some more research I should be able to fix this (using this post). Note that WP_Cron setted to daily is impossible to control exactly at what time the creation happen. If no one visit your site on night the first user on morning will experience a very long page loading ...


5

Depending on what kind of HTML you're expecting, there are different tools you can use: esc_html() escapes entire HTML blocks so you don't end up with breaking characters in your JSON object literals. esc_html_e() escapes (as above) and translates the string if you're concerned about localization in that context. wp_kses() will parse the HTML string and ...


4

There are two parts to the solution here. You need to use a JSON API custom controller In your custom controller, you'll need to decide how to pass the meta_query data structure Depending on how robust you need this to be, you could use a variety of approaches. Here is the maximalist approach, that will allow any kind of meta_query, encoding the ...


3

For the record, I'm not sure why anyone would use the JetPack JSON API as it currently works for a self hosted site. If you're doing AJAX and JSON, the whole point is to get back some JSON data FAST. Using jetpack involves an unnecessary call to wordpress.com, which then does a call to your own self hosted blog. Using the wonderful JSON API plugin, you ...


3

You can add your own AJAX API for do_shortcode. Add this to a suitable location (i.e. functions.php or a plugin): add_action('wp_ajax_doshortcode', 'ajax_doshortcode'); function doshortcode() { echo do_shortcode($_POST['text']); die(); // this is required to return a proper result } And this to your Javascript: $.ajax({ url : ajaxurl, data : { ...


3

The AJAX request would query for the dates it requires to display. With Lazy fetching set, if you switch from month to week or day views it won't bother making another request, since it doesn't need to. This is outlined in the fullcalendar documentation. As for using this method, see this question on how to obtain the admin-ajax.php url properly. Next, you ...


3

Doesn't look like there's any way to avoid it. The update_metadata() function, which is ultimately responsible for saving the meta, explicitly runs a stripslashes_deep() on the meta value. This function will even strip slashes from array elements, if the value were an array. Theres a filter that's run AFTER that called sanitize_meta, which you could hook ...


3

The problem will likely be a (very slow) callback that is attached to your get_the_excerpt() function. To inspect the attached callbacks, just inspect the global: // Best hooked to `shutdown` echo '<pre>'.var_export( $GLOBALS['wp_filters']['get_the_excerpt'], true ).'</pre>'; Then get rid of all those callbacks.


3

I have used symbolic links for convenience for awhile on a dev server but they are not 100% reliable as some PHP functions will return the filesystem path of the target instead of the path to the symlink itself. The most notable example (though not really a function) is the magic constant __FILE__. (Also https://bugs.php.net/bug.php?id=46260) That can cause ...


2

Since you're already using Python, I recommend grabbing a Python XML-RPC library and building a request into your scraper. We actually added support for creating new custom post type entries in WordPress 3.4. If it helps, the documentation for Python's XML-RPC library is freely available. As is the documentation for the WordPress wp.newPost rpc call. ...


2

Ok, found. I spent hours on this but I managed to find the solution. The command I was looking for was $rss->enable_order_by_date(false);. So you should set (for benefit of the community): <?php /* include the required file */ include_once(ABSPATH . WPINC . '/feed.php'); /* specify the source feed */ $rss = fetch_feed('FEED_URL'); ...


2

Just for the record, I have used the JSON API plugin a couple months ago and it still works like a charm. Actually, now that I check they have updated the plugin in June 2013, and works very well. I like it better than JetPack because is more extensible. Also, I came across this very recently, might be worth checking out: http://thermal-api.com/.


2

In your code json_encode() function causes to add second backslash on the following line. $data = json_encode($item_data); Add the following code in place of above code so it will replace double backslashes with single backslash in data returned by json_encode function. $data = str_replace("\\\'","\\'",json_encode($item_data )); Visit following links ...


2

I tried to parse your JSON into this and got an error that you have bad escaped characters (backslash must be escaped). Taking into account Vinod Dalvi's comment, the definition of json_encode in WordPress is wrapped by function_exists(). I guess if you have PHP version of 5.2 or above (which I think you have, because you can use json_decode outside ...


2

The REST API can be used for straight-up retrieval on any blog that has enabled it. Self-hosteds require an active choice to turn the JSON interface on in Jetpack but once it's up it's wide open. This is not necessarily appreciated by everyone, and that's somewhat understandable. I picked a blog ID at random here for the /posts/ call: ...


2

To output JSON always the function json_encode( $string ). The function is not available on all hosts. Don't worry, WordPress offers a fallback in wp-includes/compat.php. That's a wrapper for class Services_JSON::encodeUnsafe() (see wp-includes/class-json.php). If you take a look at the source you'll see: It's not a trivial job to encode a string. :) There ...


2

If you want to access the POST object directly, you can global $post and directly access the post object being used. while( have_posts() ){ the_post(); global $post; echo $post->post_excerpt; } If you are experiencing problems due to filters or anything else in the system, this should fix it.


2

I had to do the same thing. I used the JSON API plugin and had to create a new controller for JSON API that read the specific data out of the tables that All-in-One created. Unfortunately there really were not the right calls in the calendar plugin to access all the data (or at least on the older version I used this for) so I had to write the whole ...


2

Use wp_remote_get() in conjunction with wp_remote_retrieve_body() Example <?php $request = wp_remote_get('http://example.com'); $response = wp_remote_retrieve_body( $request ); echo $response; ?> Check the documentation for possible arguements


2

Unfortunately you can't use Vagrantpress and Composer directly together easily. Half of Vagrantpress is the WordPress setup itself which isn't compatible. If you still wanted to leverage the base work Vagrantpress has done with PHP, Apache, MySQL etc, you could fork it and modify their WP module found here: ...


2

wp_send_json() handles all parts of returning content in an AJAX call. First off, it sets the content type of the returned content to application/json with the proper charset. Secondly, it automatically calls wp_die() after sending the JSON result, which is necessary in an AJAX call in WordPress. You could consider using wp_send_json_success() for ...


1

In addition to @birgire reply, placing the filter code somewhere can be tricky: If you place it under your theme's "functions.php" file, a theme update could overwrite your code Writing a plugin for just adding a filter is a lot of fuzz This is why what I did was to use the following plugin that allows you to write your custom actions and filters within ...


1

Normally, when one want to put strings to be used in javascript, esc_js is the right function, not esc_attr. The problem is that esc_js, according to docs: Escapes text strings for echoing in JS (bold mine). So, using with esc_js you obtain a string that can be safely echoed in js, not parsed: it's not a bug, it's the intended behaviour. The ...



Only top voted, non community-wiki answers of a minimum length are eligible