I hope someone can help me out.
I'm working on a website where I installed Wordpress. On the frontpage I have a small div where I want to output the first 10 words from another page with pageID. At the moment it's almost working but instead of loading in 10 words it's loading in 10 letters.
Example:
Instead of: Hello my name is Erwin and this is a test
It loads: Hello my nam
What am I doing wrong?
I Use the following php in functions.php:
if(!function_exists('getPageContent'))
{
function getPageContent($pageId,$num_words)
{
if(!is_numeric($pageId))
{
return;
}
global $wpdb;
$nsquery = 'SELECT DISTINCT * FROM ' . $wpdb->posts .
' WHERE ' . $wpdb->posts . '.ID=' . $pageId;
$post_data = $wpdb->get_results($nsquery);
if(!empty($post_data))
{
foreach($post_data as $post)
{
$text_out=nl2br($post->post_content);
$text_out=str_replace(']]>', ']]>', $text_out);
$text_out = strip_tags($text_out);
return substr($text_out,0,$num_words);
}
}
}}
And I use the following string to load in the content:
(Where 89 is my Page ID)
echo getPageContent(89,10);