{"id":1976,"date":"2013-06-26T13:04:26","date_gmt":"2013-06-26T13:04:26","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=1976"},"modified":"2013-06-26T13:04:26","modified_gmt":"2013-06-26T13:04:26","slug":"retrieve-content-wordpress-database","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2013\/06\/26\/retrieve-content-wordpress-database\/","title":{"rendered":"How to retrieve content from a WordPress database directly"},"content":{"rendered":"            <script type=\"text\/javascript\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/plugins\/wordpress-code-snippet\/scripts\/shBrushPhp.js\"><\/script>\n<p>WordPress is the world&#8217;s most popular blogging platform and is used by millions of websites. It has been converted and customized to almost any kind of website imaginable. This article is if you want to retrieve content from a WP database without having to go through WP code or functions. Just straight access to the WP database using SQL.<\/p>\n<p>We take two example cases of extracting posts from WP:<\/p>\n<ol>\n<li>Just browsing posts as per the posted data<\/li>\n<li>Retrieving posts using tags to search for matching posts<\/li>\n<\/ol>\n<p>Both the above cases fetch the same data. What they retrieve are:<\/p>\n<ul>\n<li>The url to the actual post<\/li>\n<li>The featured image if any<\/li>\n<li>The post title<\/li>\n<li>The post content<\/li>\n<\/ul>\n<p>As a side-feature, any images in the post content are removed. This line can be commented out if required. Its just that the method of retrieval is different.<\/p>\n<h2>WordPress Database Schema<\/h2>\n<p>Give below is the database schema diagram, generated by <a title=\"Socrates\" href=\"https:\/\/truelogic.org\/wordpress\/2012\/08\/02\/socrates-the-only-online-mysql-schema-diagram-generator\/\" target=\"_blank\">Socrates<\/a><\/p>\n<p><a href=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2013\/06\/2013-06-26-16-59-482.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-1982\" alt=\"2013-06-26 16-59-48\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2013\/06\/2013-06-26-16-59-482-1024x808.png\" width=\"624\" height=\"492\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2013\/06\/2013-06-26-16-59-482-1024x808.png 1024w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2013\/06\/2013-06-26-16-59-482-300x236.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2013\/06\/2013-06-26-16-59-482.png 1138w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<h2><\/h2>\n<h2><\/h2>\n<h2><\/h2>\n<h2>Browse Posts<\/h2>\n<p>The code below shows how to extract posts as per posted data. You can set the limit of posts to fetch.<br \/>\n<pre class=\"brush: php\">&lt;?php\r\n\r\n\r\n$no_of_news_items = 10;\r\n$g_connServer=&quot;localhost&quot;;\r\n$wp_uid  = &quot;userid&quot;;\r\n$wp_pwd = &quot;password&quot;;\r\n$wp_db = &quot;database&quot;;\r\n\r\n\r\n\t$wconnData = mysql_connect($g_connServer, $wp_uid, $wp_pwd);\r\n\t\tif ($wconnData) {\r\n\t\t\t$wdb =mysql_select_db($wp_db, $wconnData);\r\n\t\t\tif ($wdb) {\r\n\r\n\t\t\t\t\t$sql = &quot;select * from wp_posts where post_status =&#039;publish&#039; and post_date &lt;= now() order by ID desc limit 0,&quot; .$no_of_news_items;\r\n\t\t\t\t\t\t$rst = mysql_query($sql, $wconnData);\r\n\t\t\t\t\t\tif ($rst) {\r\n\t\t\t\t\t\t\t\t\t\/\/ get WP base url\r\n\t\t\t\t\t\t\t$sql = &quot;select option_value from wp_options where option_name=&#039;siteurl&#039;&quot;;\r\n\t\t\t\t\t\t\t$rst2 = mysql_query($sql, $wconnData);\r\n\r\n\t\t\t\t\t\t\twhile ($row2 = mysql_fetch_assoc($rst2)) {\r\n\t\t\t\t\t\t\t\t$wp_base = $row2[&quot;option_value&quot;] . &quot;\/wp-content\/uploads&quot;;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmysql_free_result($rst2);\r\n\r\n\t\t\t\t\t\t\t\t\t\/\/ get matching posts\r\n\t\t\t\t\t\t\t$arrData = array();\r\n\t\t\t\t\t\t\t$i = 0;\r\n\t\t\t\t\t\t\twhile ($row = mysql_fetch_assoc($rst)) {\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;link&quot;] = $row[&quot;guid&quot;];\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;id&quot;] = $row[&quot;ID&quot;];\r\n\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;title&quot;] = $row[&quot;post_title&quot;];\r\n\r\n\t\t\t\t\t\t\t\t$t = trim($row[&quot;post_content&quot;]);\r\n\t\t\t\t\t\t\t\t$t = preg_replace(&quot;\/&lt;img[^&gt;]+\\&gt;\/i&quot;, &quot;&quot;, $t); \/\/ remove any images in text\r\n\t\t\t\t\t\t\t\tif (strlen($t) &gt; 200)  \/\/ truncate text to 200 chars\r\n\t\t\t\t\t\t\t\t\t$t = truncateText($t, 200) ;\r\n\r\n\t\t\t\t\t\t\t\t$t .= &quot;&nbsp;&lt;a href=&#039;&quot; . $row[&quot;guid&quot;] .&quot;&#039; target=_blank&gt;[Read More..]&lt;\/a&gt;&quot;;\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;content&quot;] = $t;\r\n\t\t\t\t\t\t\t\t\r\n\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\/\/ get featured image\r\n\t\t\t\t\t\t\t\t\t$sql = &quot;select meta_value from wp_postmeta where post_id = &quot; . $row[&quot;ID&quot;] . &quot; and  meta_key = &#039;_thumbnail_id&#039; limit 0,1&quot;;\r\n\t\t\t\t\t\t\t\t\t$rst2 = mysql_query($sql, $wconnData);\r\n\t\t\t\t\t\t\t\t\tif ($rst2) {\r\n\t\t\t\t\t\t\t\t\t\twhile ($row2 = mysql_fetch_assoc($rst2)) {\r\n\t\t\t\t\t\t\t\t\t\t\t$image_id = $row2[&quot;meta_value&quot;];\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\tmysql_free_result($rst2);\r\n\r\n\t\t\t\t\t\t\t\t\t\t$sql = &quot;select * from wp_postmeta where post_id=&quot; . $image_id . &quot; and meta_key = &#039;_wp_attached_file&#039;&quot;;\r\n\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t$rst3 = mysql_query($sql, $wconnData);\r\n\t\t\t\t\t\t\t\t\tif ($rst3) {\r\n\t\t\t\t\t\t\t\t\t\twhile ($row3 = mysql_fetch_assoc($rst3)) {\r\n\t\t\t\t\t\t\t\t\t\t\t$image_path= $row3[&quot;meta_value&quot;];\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\tmysql_free_result($rst3);\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;featured_image&quot;] = $wp_base . &quot;\/&quot; . $image_path;\r\n\t\t\t\t\t\t\t\t$i++;\t\r\n\r\n\t\t\t\t\t\t\t} \/\/ \twhile ($row = mysql_fetch_assoc($rst)) {\r\n\r\n\t\t\t\t\t\t\tmysql_free_result($rst);\r\n\r\n\t\t\t\t\t\t\tmysql_close($wconnData);\r\n\r\n\r\n\t\t\t\t\t\t} \/\/ if($rst)\t\t\r\n\t\r\n\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\texit(&quot;Error opening database&quot;);\r\n\t\t}\r\n\t\telse\r\n\t\t\texit( &quot;Error opening connection&quot;);\r\n\r\nfunction truncateText($text, $maxlen) {\r\n\t$retVal = &quot;&quot;;\r\n\t$delimiters = array(&quot;.&quot;, &quot; &quot;, &quot;,&quot;, &quot;!&quot;, &quot;\\n&quot;, &quot;?&quot;);\r\n\t\r\n\tif (strlen($text) &lt;= $maxlen)\r\n\t\t$retVal = $text;\r\n\telse {\r\n\t\t$i = $maxlen;\r\n\t\twhile(!in_array(substr($text,$i, 1), $delimiters))\r\n\t\t{\r\n\t\t\t$i = $i+1;\r\n\t\t}\r\n\t\t$retVal = substr($text,0,$i);\r\n\t\t\r\n\t}\t\t\t\t\r\n\t\r\n\treturn $retVal;\r\n}\r\n\r\n\t\r\n?&gt;\r\n\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;&lt;\/title&gt;\r\n\r\n&lt;style&gt;\r\n.wp_news_block_heading {\r\n\twidth: 600px;\r\n\theight: auto;\r\n\tpadding:5px;\r\n\tbackground-color:#e5e5e5;\r\n\tcolor:#343434;\r\n\tpadding-left:10px;\r\n\tfont-family;arial;\r\n\tfont-size:15px;\r\n\tfont-weight:bold;\r\n\ttext-transform:capitalize;\r\n}\r\n.wp_news_block {\r\n\twidth: 600px;\r\n\theight: 120px;\r\n\tmargin-top: 20px;\r\n\tborder-bottom:1px solid #e5e5e5;\r\n}\r\n\r\n.wp_news_block .image {\r\n\tfloat:left;\r\n\twidth:150px;\r\n\tpadding:5px;\r\n\theight:120px;\r\n}\r\n\r\n.wp_news_block .data {\r\n\tfloat:right;\r\n\twidth:420px;\r\n\tpadding-left:5px;\r\n\tmargin:0;\r\n\tfont-size:14px;\r\n\theight:120px;\r\n\r\n}\r\n\r\n.wp_news_block .data a{\r\n\r\n}\r\n\r\n.wp_news_block .data .heading {\r\n\tfont-size:18px;\r\n\tfont-weight:bold;\r\n\tmargin-bottom:10px;\r\n\r\n}\r\n\r\n.wp_news_block .data .text {\r\n\tfont-size:12px;\r\n\tcolor: #846d78;\r\n\r\n}\r\n\r\n\r\n\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\t\r\n&lt;body&gt;\r\n\t&lt;div class=&quot;wp_news_block_heading&quot;&gt;SOME HEADING COMES HERE&lt;\/div&gt;\r\n\t&lt;?php \r\n\t\tfor($i= 0; $i &lt;count($arrData); $i++) {\r\n\t\t\t$single = $arrData[$i];\r\n\t\t\t?&gt;\r\n\t\t\t&lt;div class=&quot;wp_news_block&quot;&gt;\r\n\t\t\t\t&lt;div class=&quot;image&quot;&gt;\r\n\t\t\t\t\t&lt;a href=&#039;&lt;?php echo($single[&quot;link&quot;]);?&gt;&#039; target=_blank&gt;&lt;img src=&quot;&lt;?php echo($single[&quot;featured_image&quot;]);?&gt;&quot; border=0 align=left width=150 height=112&gt;&lt;\/a&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;data&quot;&gt;\r\n\t\t\t\t\t&lt;div class=&quot;heading&quot;&gt;\r\n\t\t\t\t\t\t&lt;?php echo($single[&quot;title&quot;]);?&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t\t&lt;div class=&quot;text&quot;&gt;\r\n\t\t\t\t\t\t&lt;?php echo($single[&quot;content&quot;]);?&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\t\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;spacer&quot;&gt;&lt;\/div&gt;\r\n\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;div class=&quot;spacer_large&quot;&gt;&lt;\/div&gt;\r\n\r\n\t\t\r\n\t&lt;?php \t}\t?&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre><\/p>\n<h2>Search Posts With Tags<\/h2>\n<p>In this case we retrieve posts based on matching tags. Eg.we create a tag string with the value &#8220;music,pop,rock&#8221; and this code will go and retrieve the posts which have either of these tags.<br \/>\n<pre class=\"brush: php\">&lt;?php\r\n\r\n\r\n$no_of_news_items = 10;\r\n$g_connServer=&quot;localhost&quot;;\r\n$wp_uid  = &quot;userid&quot;;\r\n$wp_pwd = &quot;password&quot;;\r\n$wp_db = &quot;database&quot;;\r\n\r\n$wp_tags = &quot;tag1,tag2&quot;; \/\/ tags separated by commas\r\n\r\n\t$wconnData = mysql_connect($g_connServer, $wp_uid, $wp_pwd);\r\n\t\tif ($wconnData) {\r\n\t\t\t$wdb =mysql_select_db($wp_db, $wconnData);\r\n\t\t\tif ($wdb) {\r\n\r\n\t\t\t\tif (strpos($wp_tags, &quot;,&quot;) !== false) {\r\n\t\t\t\t\t$arrtags = explode(&quot;,&quot;, $wp_tags);\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t\t$arrtags[] = $wp_tags;\r\n\r\n\t\t\t\t\r\n\t\t\t\t$sql = &quot;select term_id from wp_terms where (&quot;;\r\n\t\t\t\tforeach($arrtags as $t) {\r\n\t\t\t\t\tif ($t != &#039;&#039;)\r\n\t\t\t\t\t\t$sql .= &quot; name=&#039;&quot; . $t . &quot;&#039; or &quot;;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (strpos($sql, &quot;or&quot;) !== false)\r\n\t\t\t\t\t$sql = substr($sql, 0, strlen($sql)-3);\r\n\t\t\t\t$sql .= &quot;)&quot;;\r\n\t\t\t\t\r\n\t\t\t\t$rst = mysql_query($sql, $wconnData);\r\n\t\t\t\tif ($rst) {\r\n\t\t\t\t\t$term_ids = &#039;&#039;;\r\n\r\n\t\t\t\t\twhile ($row = mysql_fetch_assoc($rst)) {\r\n\t\t\t\t\t\t$term_ids .= $row[&#039;term_id&#039;] . &quot;,&quot;;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tmysql_free_result($rst);\r\n\r\n\t\t\t\t\tif (strpos($term_ids, &quot;,&quot;) !== false)\r\n\t\t\t\t\t\t$term_ids = substr($term_ids, 0, strlen($term_ids)-1);\r\n\r\n\t\t\t\t\r\n\t\t\t\t\t$sql = &quot;select object_id from wp_term_relationships where term_taxonomy_id in (&quot; . $term_ids . &quot;)&quot;;\r\n\t\t\t\t\tif ($term_ids != &#039;&#039;)\r\n\t\t\t\t\t\t$rst = mysql_query($sql, $wconnData);\r\n\t\t\t\t\tif ($rst) {\r\n\t\t\t\t\t\t$object_ids = &#039;&#039;;\r\n\r\n\t\t\t\t\t\twhile ($row = mysql_fetch_assoc($rst)) {\r\n\t\t\t\t\t\t\t$object_ids .= $row[&#039;object_id&#039;] . &quot;,&quot;;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tmysql_free_result($rst);\r\n\r\n\t\t\t\t\t\tif (strpos($object_ids, &quot;,&quot;) !== false)\r\n\t\t\t\t\t\t\t$object_ids = substr($object_ids, 0, strlen($object_ids)-1);\t\t\t\t\t\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t$sql = &quot;select * from wp_posts where post_status =&#039;publish&#039; and ID in (&quot; . $object_ids . &quot;) order by ID desc limit 0,&quot; .$no_of_news_items;\r\n\t\t\t\t\t\t$rst = mysql_query($sql, $wconnData);\r\n\t\t\t\t\t\tif ($rst) {\r\n\t\t\t\t\t\t\t\t\t\/\/ get WP base url\r\n\t\t\t\t\t\t\t$sql = &quot;select option_value from wp_options where option_name=&#039;siteurl&#039;&quot;;\r\n\t\t\t\t\t\t\t$rst2 = mysql_query($sql, $wconnData);\r\n\r\n\t\t\t\t\t\t\twhile ($row2 = mysql_fetch_assoc($rst2)) {\r\n\t\t\t\t\t\t\t\t$wp_base = $row2[&quot;option_value&quot;] . &quot;\/wp-content\/uploads&quot;;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tmysql_free_result($rst2);\r\n\r\n\t\t\t\t\t\t\t\t\t\/\/ get matching posts\r\n\t\t\t\t\t\t\t$arrData = array();\r\n\t\t\t\t\t\t\t$i = 0;\r\n\t\t\t\t\t\t\twhile ($row = mysql_fetch_assoc($rst)) {\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;link&quot;] = $row[&quot;guid&quot;];\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;id&quot;] = $row[&quot;ID&quot;];\r\n\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;title&quot;] = $row[&quot;post_title&quot;];\r\n\r\n\t\t\t\t\t\t\t\t$t = trim($row[&quot;post_content&quot;]);\r\n\t\t\t\t\t\t\t\t$t = preg_replace(&quot;\/&lt;img[^&gt;]+\\&gt;\/i&quot;, &quot;&quot;, $t); \/\/ remove images in text\r\n\t\t\t\t\t\t\t\tif (strlen($t) &gt; 200)  \/\/ truncate text at 200 chars\r\n\t\t\t\t\t\t\t\t\t$t = truncateText($t, 200) ;\r\n\r\n\t\t\t\t\t\t\t\t$t .= &quot;&amp;nbsp;&lt;a href=&#039;&quot; . $row[&quot;guid&quot;] .&quot;&#039; target=_blank&gt;[Read More..]&lt;\/a&gt;&quot;;\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;content&quot;] = $t;\r\n\t\t\t\t\t\t\t\t\r\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\/\/ get featured image\r\n\t\t\t\t\t\t\t\t\t$sql = &quot;select meta_value from wp_postmeta where post_id = &quot; . $row[&quot;ID&quot;] . &quot; and  meta_key = &#039;_thumbnail_id&#039; limit 0,1&quot;;\r\n\t\t\t\t\t\t\t\t\t$rst2 = mysql_query($sql, $wconnData);\r\n\t\t\t\t\t\t\t\t\tif ($rst2) {\r\n\t\t\t\t\t\t\t\t\t\twhile ($row2 = mysql_fetch_assoc($rst2)) {\r\n\t\t\t\t\t\t\t\t\t\t\t$image_id = $row2[&quot;meta_value&quot;];\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\tmysql_free_result($rst2);\r\n\r\n\t\t\t\t\t\t\t\t\t\t$sql = &quot;select * from wp_postmeta where post_id=&quot; . $image_id . &quot; and meta_key = &#039;_wp_attached_file&#039;&quot;;\r\n\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t$rst3 = mysql_query($sql, $wconnData);\r\n\t\t\t\t\t\t\t\t\tif ($rst3) {\r\n\t\t\t\t\t\t\t\t\t\twhile ($row3 = mysql_fetch_assoc($rst3)) {\r\n\t\t\t\t\t\t\t\t\t\t\t$image_path= $row3[&quot;meta_value&quot;];\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\tmysql_free_result($rst3);\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t$arrData[$i][&quot;featured_image&quot;] = $wp_base . &quot;\/&quot; . $image_path;\r\n\t\t\t\t\t\t\t\t$i++;\t\r\n\r\n\t\t\t\t\t\t\t} \/\/ while ($row = mysql_fetch_assoc($rst)) {\r\n\r\n\t\t\t\t\t\t\tmysql_free_result($rst);\r\n\r\n\t\t\t\t\t\t\tmysql_close($wconnData);\r\n\r\n\r\n\t\t\t\t\t\t}\t \/\/ \tif ($rst) {\r\n\t\r\n\t\t\t\t\t\telse {\r\n\t\t\t\t\t\t\t\/\/exit(&quot;Error: could not fetch posts&quot;);\r\n\t\t\t\t\t\t}\t\r\n\r\n\t\t\t\t\t}\t\/\/ \tif ($rst) {\r\n\t\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\texit(&quot;Error: could not fetch object_id&quot;);\r\n\t\t\t\t\t}\t\r\n\t\t\t\t\r\n\t\t\t\t} \/\/ \tif ($rst) {\r\n\r\n\t\t\t\telse {\r\n\t\t\t\t\texit(&quot;Error: could not fetch term_id&quot;);\r\n\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\texit(&quot;Error opening database&quot;);\r\n\t\t}\r\n\t\telse\r\n\t\t\texit( &quot;Error opening connection&quot;);\r\n\r\n\r\nfunction truncateText($text, $maxlen) {\r\n\t$retVal = &quot;&quot;;\r\n\t$delimiters = array(&quot;.&quot;, &quot; &quot;, &quot;,&quot;, &quot;!&quot;, &quot;\\n&quot;, &quot;?&quot;);\r\n\t\r\n\tif (strlen($text) &lt;= $maxlen)\r\n\t\t$retVal = $text;\r\n\telse {\r\n\t\t$i = $maxlen;\r\n\t\twhile(!in_array(substr($text,$i, 1), $delimiters))\r\n\t\t{\r\n\t\t\t$i = $i+1;\r\n\t\t}\r\n\t\t$retVal = substr($text,0,$i);\r\n\t\t\r\n\t}\t\t\t\t\r\n\t\r\n\treturn $retVal;\r\n}\r\n\r\n\t\r\n?&gt;\r\n\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;&lt;\/title&gt;\r\n\r\n&lt;style&gt;\r\n.wp_news_block_heading {\r\n\twidth: 600px;\r\n\theight: auto;\r\n\tpadding:5px;\r\n\tbackground-color:#e5e5e5;\r\n\tcolor:#343434;\r\n\tpadding-left:10px;\r\n\tfont-family;arial;\r\n\tfont-size:15px;\r\n\tfont-weight:bold;\r\n\ttext-transform:capitalize;\r\n}\r\n.wp_news_block {\r\n\twidth: 600px;\r\n\theight: 120px;\r\n\tmargin-top: 20px;\r\n\tborder-bottom:1px solid #e5e5e5;\r\n}\r\n\r\n.wp_news_block .image {\r\n\tfloat:left;\r\n\twidth:150px;\r\n\tpadding:5px;\r\n\theight:120px;\r\n}\r\n\r\n.wp_news_block .data {\r\n\tfloat:right;\r\n\twidth:420px;\r\n\tpadding-left:5px;\r\n\tmargin:0;\r\n\tfont-size:14px;\r\n\theight:120px;\r\n\r\n}\r\n\r\n.wp_news_block .data a{\r\n\r\n}\r\n\r\n.wp_news_block .data .heading {\r\n\tfont-size:18px;\r\n\tfont-weight:bold;\r\n\tmargin-bottom:10px;\r\n\r\n}\r\n\r\n.wp_news_block .data .text {\r\n\tfont-size:12px;\r\n\tcolor: #846d78;\r\n\r\n}\r\n\r\n\r\n\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\t\r\n&lt;body&gt;\r\n\t&lt;div class=&quot;wp_news_block_heading&quot;&gt;SOME HEADING COMES HERE&lt;\/div&gt;\r\n\t&lt;?php \r\n\t\tfor($i= 0; $i &lt;count($arrData); $i++) {\r\n\t\t\t$single = $arrData[$i];\r\n\t\t\t?&gt;\r\n\t\t\t&lt;div class=&quot;wp_news_block&quot;&gt;\r\n\t\t\t\t&lt;div class=&quot;image&quot;&gt;\r\n\t\t\t\t\t&lt;a href=&#039;&lt;?php echo($single[&quot;link&quot;]);?&gt;&#039; target=_blank&gt;&lt;img src=&quot;&lt;?php echo($single[&quot;featured_image&quot;]);?&gt;&quot; border=0 align=left width=150 height=112&gt;&lt;\/a&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;data&quot;&gt;\r\n\t\t\t\t\t&lt;div class=&quot;heading&quot;&gt;\r\n\t\t\t\t\t\t&lt;?php echo($single[&quot;title&quot;]);?&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t\t&lt;div class=&quot;text&quot;&gt;\r\n\t\t\t\t\t\t&lt;?php echo($single[&quot;content&quot;]);?&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\t\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=&quot;spacer&quot;&gt;&lt;\/div&gt;\r\n\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;div class=&quot;spacer_large&quot;&gt;&lt;\/div&gt;\r\n\r\n\t\t\r\n\t&lt;?php \t}\t?&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre><\/p>\n<p>The truncate() function is a small function which truncates a string only at a word boundary instead of cutting it in the middle of a word.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>WordPress is the world&#8217;s most popular blogging platform and is used by millions of websites. It has been converted and customized to almost any kind <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2013\/06\/26\/retrieve-content-wordpress-database\/\" title=\"How to retrieve content from a WordPress database directly\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1979,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,11],"tags":[],"class_list":["post-1976","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apachephp","category-tutorials"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/1976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=1976"}],"version-history":[{"count":12,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/1976\/revisions"}],"predecessor-version":[{"id":1991,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/1976\/revisions\/1991"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/1979"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=1976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=1976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=1976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}