Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Hello!

    I’m using print_custom_field but it returns nothing!
    Here’s my code:

    <?php
          $Q = new GetPostsQuery();
          $args = array();
          $args['post_type'] = 'whitepaper';
          $args['post_status'] = 'publish';
          $args['orderby'] = 'ID';
          $args['limit'] = '8';
    
          $results = $Q->get_posts($args);
    
          foreach ($results as $r):
    ?>
    
    <a href="<?php print_custom_field('whitepaperFile:get_post','_wp_attached_file'); ?>" class="download" title="Download">Download</a>
    
    <?php endforeach; ?>

    Although if I try to print the custom field, it shows a number, which I believe it’s the unique ID.

    The following code shows the unique ID:

    <?php print $r['whitepaperFile']; ?>

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    This is just data relations 101 and if I had a nickel… you need to convert that ID to what you want to see. There are lots of WP functions that do this, and there are a few CCTM functions that try to make it easier. If your custom relation field is named
    “whitepaperFile”, then yes, that’s the ID of your related post or image or media item.

    E.g. here’s how you might use the CCTM’s get_post filter to lookup data on the post referenced by the whitepaperFile ID:

    foreach ($results as $r):
        $myfile = CCTM::filter($r['whitepaperFile'], 'get_post');
        print_r($myfile);
    endforeach;

    The print_r there will print out the data attributes available to you. Figure out which one you need and print it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I get the actual link to the attachment’ is closed to new replies.