The_title() Wordpress using in php script -


i'm trying the_title(); wordpress page use in php script

my code:

<?php    global $post;   $args = array( 'numberposts' => 10, 'category_name' => 'bin-o' );   $posts = get_posts( $args );   foreach( $posts $post ): setup_postdata($post); ?>     $project_name = the_title();     $post_id = get_page_id('$project_name');     var_dump($project_name); ?>  <a href="<?php echo get_site_url() . '/?p=' .  $post_id  ?>"><h1><?php the_title() ?></h1> <?php the_content() ?></a> 

the functions.php:

<?php     // id of page name   function get_page_id($page_name){     global $wpdb;     $page_name = $wpdb->get_var("select id $wpdb->posts post_name = '".$page_name."'");     return $page_name;   } ?> 

the problem gives the_title() when printed. can't use the_title() use php script cause the_title return null

how can fix can use requested title use further in php script

you use get_the_title().

many wordpress in-loop functions have corresponding get_ versions, return value, instead of echoing it.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -