Support

Account

Home Forums General Issues Pulling in page_id from page link field type

Solving

Pulling in page_id from page link field type

  • Hey there,

    I’ve looked for the solution to my problem online and could not find so came here to maybe find an answer.

    I used the “page link” field type and I’m pulling in different pages to show as a list,

    My problem is that I’m not sure how to pull the page_id from that page link I selected.
    I’ve got my Code below to clarify:

     
    $links = get_field('procedure_list');
    <?php 
                    if($links): ?>
    
                    <h3 class="procedures-menu_header">Procedures</h3>
                    <ul class="procedures-menu_list">
    
                        <?php foreach( $links as $links): ?>
                            <li class="procedures-menu_list-item">
                                <a href="<?php echo $links ?>"><?php echo $links ?></a>
                            </li>
                    <?php endforeach; ?>
                    </ul>
                    <?php endif; ?>
    

    I would like to echo the title of the page the link refers to if that is possible.

    Thanks

  • If you can, simply change your page link field type to a Post Object. You can then set your post type in the settings to page which will give you the same page selection on your form. You can then use the code below to get the title as you wanted.

    
    <?php 
    $links = get_field('procedure_list');
    if( $links ): ?>
        <h3 class="procedures-menu_header">Procedures</h3>
    	<ul class="procedures-menu_list">
        <?php foreach( $links as $link): ?>
            <li>
                <a href="<?php echo get_permalink($link->ID); ?>"><?php echo get_the_title($link->ID); ?></a>
            </li>
        <?php endforeach; ?>
        </ul>
    <?php endif;
    
    ?>
  • It works,

    Thank you very much for your quick response.

    Kind regards

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

You must be logged in to reply to this topic.