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

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 ...


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

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 ...


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

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 ...


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

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

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

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

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

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 ...


2

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 : { ...


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.


1

Try wrapping your array in json_encode(): function add_map_data() { $objName = "MapData"; $array = array( "MapViewLatitude" => "51.505", "MapViewLongitude" => "-0.09", ); wp_enqueue_script( 'mapdata', get_bloginfo('template_url').'/custom/map.js', null, null, false ); ...


1

Use this function form http://www.php.net/manual/en/function.json-encode.php#80339 function json_format($json) { $tab = " "; $new_json = ""; $indent_level = 0; $in_string = false; $json_obj = json_decode($json); if($json_obj === false) return false; $json = json_encode($json_obj); $len = strlen($json); for($c ...


1

It's only for .com installations. Here's a quote from their store page: Description Browse the best original content on WordPress.com, including articles and photography on travel, art, entertainment, food, and much more. Sign in with your WordPress.com account to read blogs you follow and easily share cool content you find on the web by ...


1

You should be urlencodeing your content. Whitespace is not a valid character in URLs. If you have access to WordPress functions on the sending side you can use esc_url. I suspect that has a lot to do with your problem. Be aware that there is a character limit on $_GET strings. If you are going to be posting long content you should be sending over $_POST.


1

How to do remote requests in WordPress: Use the appropriate API First, there's the WP HTTP API, which should be used for such tasks. And second, one should never ever use the @ operator, as this one suppresses error messages or notices and will successfully lock you out from troubleshooting your bugs. Just because you can't see it, doesn't mean that it's ...


1

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'); ...


1

You have a few options. The Jetpack plugin allows you to use the WordPress REST API on self-hosted blogs (previously, it was only available to WordPress.com blogs). This is probably exactly what you are looking for. Documentation: WordPress REST API Documentation Alternatively, all self-hosted WordPress installs also have a built-in XML-RPC API that can ...



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