Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to make a dynamic button that goes to portfolio page (no matter what ID/name it has), it's currently like this:

$portfolio_page = get_option('theme_portfolio_page');
$portfolio_pid = get_page_by_title($portfolio_page);

     <a href="<?php echo get_option ('theme_portfolio_page') ?>">Voltar</a>

The problem is that it links based on the page name, and when it has space on the name it bugs... So I would need a code that links dynamically to the portfolio page by ID

When I try to change to get_page_by_id

FATAL ERROR: CALL TO UNDEFINED FUNCTION GET_PAGE_BY_ID() IN /HOME/DOMAIN/WWW/WP-CONTENT/THEMES/MYTHEME/PORTFOLIO-TEMPLATE.PHP ON LINE 46

share|improve this question
    
Whenever in doubt about a WordPress function, check the Codex, get_page_by_title, there you'd have found the correct function EAMann is referencing bellow. And checking the documentation of get_page will solve the doubt you are commenting about... –  brasofilo Feb 11 '13 at 21:42
add comment

2 Answers

That's because get_page_by_id isn't a function in WordPress.

You want get_page.

share|improve this answer
    
When I try get_page or get_page_link instead of get_page_by_title it still links trough the title –  Lucas B Feb 11 '13 at 21:17
add comment

Try using Custom fields.

1.Add the page Id as a custom field value, for example "page_id".

add the following to your template file

$post = get_post_meta( get_the_ID(), 'page_id', true );

Thus you will get the link of the page in $post

Then give this is in your anchor tag as href

<a href="<?php echo $post ?>" > Something</a>

Hope this solves your problem

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.