I'm trying to use a predefined variable (generated from an earlier sweep of the database) in wordpress' standard get_permalink( get_page_by_title) function.
I'm assuming that this is possible? But I can't get it working, it always returns the url of the current page.
For the sake of clarity below I'm just manually assigning the variable.
Code...
<?php $mypagename = "My First Page"; ?>
<a href="<?php echo esc_url( get_permalink( get_page_by_title( $mypagename ) ) ); ?>">LINK</a>
N.B - My First Page (my-first-page) does exist in the database
Any ideas where I'm going wrong or if it's not possible to do it like this do you have any other suggestions?
Many thanks!
var_dump( get_page_by_title( $mypagename ) )
. I bet you getNULL
. That's whyget_permalink
is returning the URL for the current page. Are you sure the "My First Page" page exists?