Link to Portfolio page by id instead of name

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

Topic links Wordpress

Category Web


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


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

You want get_page.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.