Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have found the full solution based on Pointy answer. to encode wordpress posts data into JSON, it can be done via one of the two codes:</p> <pre><code>&lt;?php header('Content-Type: text/html; charset: UTF-8'); require( '../English/The-Blog/wp-load.php' ); query_posts(array('posts_per_page' =&gt; 20,)); $jsonpost = array(); $i=0; if (have_posts()) : while (have_posts()) : the_post(); $jsonpost[$i]["id"] = get_the_ID(); $jsonpost[$i]["title"] = get_the_title(); $jsonpost[$i]["url"] = apply_filters('the_permalink', get_permalink()); $jsonpost[$i]["content"] = apply_filters('the_content', get_the_content()); $jsonpost[$i]["date"] = get_the_time('d F Y'); $i=$i+1; endwhile; endif; header('Content-type: application/json;'); echo json_encode($jsonpost); ?&gt; </code></pre> <p><strong><em>OR</em></strong></p> <pre><code>&lt;?php define('WP_USE_THEMES', false); require('../English/The-Blog/wp-blog-header.php'); $posts = get_posts(array( 'numberposts' =&gt; 5, 'offset' =&gt; 0, 'orderby' =&gt; 'post_date', 'order' =&gt; 'DESC', 'post_type' =&gt; 'post', 'post_status' =&gt; 'publish' )); $json = array(); if ($posts) { foreach ($posts as $post) { $ray = array(); the_post(); $ray['id'] = $post-&gt;ID; $ray['date'] = $post-&gt;post_date; $ray['contents'] = $post-&gt;post_content; $ray['title'] = $post-&gt;post_title; $json['posts'][] = $ray; } } header('Content-type: application/json;'); echo json_encode($json); ?&gt; </code></pre> <p>Both of the codes give a JSON string which can be accessed/dispalyed via jQuery like this:</p> <pre><code>&lt;script&gt; jQuery(document).ready(function($){ $(".load").click(function(){ $.getJSON( 'phpscript.php', function(data){ $('#9lessonsLinks').hide(); for (var i=0 ; i &lt; data.length ; i++) { var personne = data[i]; var div_data ="&lt;div class='box'&gt;&lt;a&gt;"+personne.url+"&lt;/a&gt;&lt;/div&gt;"; $(div_data).appendTo("#9lessonsLinks"); } $('#9lessonsLinks').fadeIn(); } ); }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload