Redirects based on a JSON file

The way I do it. Note there may be a more straightforward way. Step 1 Add a custom query_varlike this to record the redirect from/to variables function my_custom_query_vars($vars){ //this allows you to store custom variables with rediect_from and rediect_to in the url $vars[] = ‘redirect_from’; $vars[] = ‘redirect_to’; return $vars; } add_filter( ‘query_vars’, ‘my_custom_query_vars’ ); … Read more

How to get more data of a post by wp_query

WordPress has many built in functions that allow you to get whatever data you have added to your posts, whether it standard or custom. Example below: if ($query->have_posts()) { while ($query->have_posts()) { $posts = $query->get_posts(); $array[‘title’] = get_the_title(); $array[‘permalink’] = get_the_permalink(); $array[‘content’] = get_the_content(); $array[‘post_date’] = get_the_date(); if (has_post_thumbnail()) { $array[‘feat_image_url’] = wp_get_attachment_url(get_post_thumbnail_id()); } $array[‘custom_meta_1’] … Read more

JSON API and notification about registration

Set your query var notify to user (if you want to send an email to the user only) or both (if you want to send it to the user and the admin). Within the plugin controller/User.php:165 calls wp_new_user_notification with $_REQUEST[‘notify’]. wp_new_user_notification is (lucky you) a pluggable function. If you have your activation logic ready to … Read more

PHP error with a shortcode: “no suitable wrapper” for file_get_contents

Use the HTTP API: $http = wp_remote_get( ‘https://en.wikipedia.org/w/api.php?action=query&titles=Test_article&prop=revisions&rvlimit=1&format=json’ ); if ( ! $body = wp_remote_retrieve_body( $http ) ) return; if ( ! $data = json_decode( $body, true ) ) return; $date = new DateTime( $data[‘query’][‘pages’][‘746140638’][‘revisions’][0][‘timestamp’] ); return $date->format( ‘m-d-Y’ );

How to convert and use JSON data from a remote WordPress server?

On server B: $result = wp_remote_post(‘http://serverA.com/?api=json’, array( ‘method’ => ‘POST’, ‘redirection’ => 1, ‘httpversion’ => ‘1.0’, ‘blocking’ => true, ‘headers’ => array(), ‘body’ => array(), ‘cookies’ => array() )); if ( is_wp_error( $result ) ) { return ‘bad connection!’; } $json = $result[‘body’]; $posts = json_decode($json); Now you have $posts as usual php array. var_dump($posts) … Read more