WordPress.org

Ready to get started?Download WordPress

Forums

get_permalink() returns empty for certain page IDs (2 posts)

  1. TheRealBenStanley
    Member
    Posted 1 year ago #

    <ul class="stageList2">
        <li><a class="sel">Stage 1</a></li>
        <li><a href="<?php echo get_permalink(1030); ?>">Stage 2</a></li>
        <li><a href="<?php echo get_permalink(1032); ?>">Stage 3</a></li>
        <li><a href="<?php echo get_permalink(1034); ?>">Stage 4</a></li>
        <li><a href="<?php echo get_permalink(1036); ?>">Stage 5</a></li>
        <li><a href="<?php echo get_permalink(1038); ?>">Stage 6</a></li>
        <li><a href="<?php echo get_permalink(1040); ?>">Stage 7</a></li>
        <li><a href="<?php echo get_permalink(1042); ?>">Stage 8</a></li>
        <li><a href="<?php echo get_permalink(1044); ?>">Stage 9a</a></li>
        <li><a href="<?php echo get_permalink(1046); ?>">Stage 9b</a></li>
    </ul>
    
    <ul class="stageList2">
        <li><a href="<?php echo get_permalink(1048); ?>">Stage 10</a></li>
        <li><a href="<?php echo get_permalink(1050); ?>">Stage 11</a></li>
        <li><a href="<?php echo get_permalink(1052); ?>">Stage 12</a></li>
        <li><a href="<?php echo get_permalink(1054); ?>">Stage 13</a></li>
        <li><a href="<?php echo get_permalink(1056); ?>">Golf Stage 1</a></li>
        <li><a href="<?php echo get_permalink(1058); ?>">Golf Stage 2</a></li>
        <li><a href="<?php echo get_permalink(1060); ?>">Golf Stage 3</a></li>
        <li><a href="<?php echo get_permalink(1062); ?>">Golf Stage 4</a></li>
        <li><a href="<?php echo get_permalink(1064); ?>">Golf Stage 5</a></li>
        <li><a href="<?php echo get_permalink(1066); ?>">Golf Stage 6</a></li>
    </ul>

    I have this code on part of my page. I am trying to get the permalinks for these specific pages, but it returns nothing and the href attribute of the links are empty. If I use other IDs than these ones listed here, the permalinks are returned fine. Also, if I use these IDs to get a permalink on another part of the site, it is returned fine there too. There is something about this specific part of this page template and these specific page IDs that won't allow me to return the permalinks.

    Has anybody ever experienced anything like this before? Is it some kind of bug that can be fixed?

    I have moved my entire WordPress website to a new server, and these permalinks were working completely fine on the other server. I have also disabled all my plugins to see if any of them were causing any errors, but it is still not working.

    Cheers,
    Ben

  2. ubaidullahbutt
    Member
    Posted 1 year ago #

    According to the documentation http://codex.wordpress.org/Function_Reference/get_permalink, you are doing correct, but there may not pages with the ID's, check your pages' ID,s.

    If get_pamalink with ID not working then, you can use get_permalink with page like below

    <a href="<?php echo esc_url( get_permalink( get_page_by_title( 'Monthly Events' ) ) ); ?>">Monthly Events</a>

Topic Closed

This topic has been closed to new replies.

About this Topic