php - How to store the_title() values in array -


i want store the_title() values array can print them index wise want.

<?php $popularpost = new wp_query( array( 'posts_per_page' => 4, 'meta_key' =>        'wpb_post_views_count' ,'orderby' => 'meta_value_num', 'post_type'=> 'idea'           ) );        while ( $popularpost->have_posts()) : $popularpost->the_post();the_title();        endwhile;   ?> 

i tried 1 solution stackoverflow can store current post value in variable.

the_title() function prints title or returns string.

use third parameter retrieve value instead of directly printing it.

append pre defined array.

thats it!!!

parameters:

$before (string) (optional) markup prepend title. default value: ''

$after (string) (optional) markup append title. default value: ''

$echo (bool) (optional) whether echo or return title. default true echo. default value: true

<?php $popularpost = new wp_query( array( 'posts_per_page' => 4, 'meta_key' =>         'wpb_post_views_count' ,'orderby' => 'meta_value_num', 'post_type'=> 'idea' ) ); $titles = array(); while ( $popularpost->have_posts()) : $popularpost->the_post(); $titles[] = the_title('', '', false); // set third parameter false. endwhile;  var_dump($titles); ?> 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -