Home Forums General Issues Use Custom field to show an article


Use Custom field to show an article

  • Hi there.

    I’ve searched and searched, but no cigar.

    I’m going to WordPress from a site, and want to maintain my SEO rating, and is therefore making a ASPX page (php), that emmulates the previous way of showing an article with a 301 redirect.

    I have a custom field called old_article_id, on every old article, and is looking for a way to call it from a PHP page in my WordPress structure and then redirect it to the real article.

    I’m quite new to WordPress so I’ve tried many different aproaches, but isn’t is possible to query the custom field, and get the new url and redirect?

    Thanks for the answers in advance

  • Hi @hummelmose

    Firstly, when you view the page in quesiton, you will run the page.php template in your theme.

    Edit this template file and add some code like so:

    $url = get_field('old_article_id');
    var_dump( $url );

    Do you see your url? If so, you can easily redirect via PHP. WP even has a function called wp_redirect I believe

  • The url I need to redirect is:


    I have solved the “make php answer aspx calls” part, but what I need, is to get the article parameter and then lookup ind the wordpress post db finding my old_article_id, and then on that part redirect to the new url with a 301 redirect.

  • Hi @hummelmose

    Sorry, did you understand my previous comment? Seems like you have gone in a completely different direction to what I have just said.

    WP looks at the URL and then runs the appropriate template. On the template you can use ACF to load the custom field data.

    If this is not what you want, please re-describe your question with more clarity.


  • I tried my best to describe 🙂

    I currently run a site on another CMS (.net). The current url to call articles is /indhold/templates/design.aspx?articleid=9713&zoneid=5.

    So i want my new wordpress site to be able to also answer the url above, and then redirect to the new wordpress url.

    So when people calling. the above url the code looks up the post with the custom field old_article_id 9713 and then redirects to the new wordpress url.

    It’s to maintain SEO. The page will make a 301 redirection, so that google on the long run finds our more than 10.000 articles on their new place.

    Hopes that explains.

  • Hi @hummelmose

    Thanks for the clarification. This is how I would do it.

    Add an action to the wp action. This action is run when WP is ready to function.
    Look at the URL (find the url in the $_SERVER array) and check if the url follows your above pattern. You can check for a patern with regexp.

    After the matching is done and you have a variable holding the $article_id, your next step is to find the post that has a matching custom field value.

    You can query the WP posts with teh get_posts function as shown here:

    Then, once you have the $post object, you can redirect to it like so:

    wp_redirect( get_permalink( $post->ID ) );

    I hope the above makes sense. You may need to get some help from a PHP / WP dev if you can’t get it to work.

    Good luck mate.


  • Thanks.

    WordPress is really a new world to me, but I do fint Advanced Custom Fields to be one of the premier plugins needed to be dynamic enough 🙂

    Thanks a mill for your guidance.


Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Use Custom field to show an article’ is closed to new replies.