My page title is This is my title
, if I try and retrieve the ID from the title like this then it does not work:
$mytitle = 'This is my title';
$mytitle2 = get_page_by_title( $mytitle, OBJECT, 'mycustompost' );
print_r($mytitle2);
But if I do this it does work:
$mytitle2 = get_page_by_title( 'This is my title', OBJECT, 'mycustompost' );
print_r($mytitle2);
What gives? Does get_page_by_title
not accept variables?
print_r
byvar_dump
so that you'll getNULL
result if no post is found.$y = 'Sample Page'; $x = get_page_by_title( $y , OBJECT, 'page' ); var_dump( $x );
You should double check your code (and post type)