Getting links to work the same on development and production

I am working on a website where I am specifying links to pages within my site in other pages.

I am using the same permalink post name structure i.e. http://example.com/sample-post on both development and production and I am using /index.php/sample-post/ to link to a specific blog. This works on production but not on development.

My development machine’s wordpress install is under a directory called wordpress and is running off a URL http://127.0.1.1:8080/wordpress/

On development for some reason when I specify /index.php/sample-post the wordpress part of the site url is absent. This only seems to happen with posts and not pages.

As far as I know /index.php/ refers to the site url which should be http://127.0.1.1:8080/wordpress/ unless I am mistaken. Moreover I would like to know if there is any alternative way to specify absolute URLs in wordpress and get around this problem.

Thanks in advance.
nav

2 Answers
2

Suggestion:

I suppose that you have a backend interface that use custom fields to do this.

Don’t use permalinks in this fields, instead save the post_id of the page that you want to link in the custom field and use get_permalink() in your code

Example:
Custom field name: link_to_page

In your code, use, for example

echo get_permalink(get_post_meta($post->post_id,'link_to_page',true))

In the backend, you can use custom meta boxes. See this article for reference on how to implemente custom meta boxes

Leave a Comment