• Hello,

    I have some posts in a certain category and with a certain custom field. These posts have a title and as post body they have a link. Just a link.

    I want to get these kind of posts in another post from another category and display them as hyperlinks, with their title as anchor text and their post bodies as the target address.

    I guess this can be achieved by inserting a code in the template, in single.php which should contain a new loop to display the posts by category and by the value of the custom field.

    Anyone has an idea about what this code should look like?
    Any suggestion or advice on achieving this is more than welcomed. If you need more details about what I’m trying to do, don’t hesitate to ask them.

    Thank you,
    Chris

Viewing 5 replies - 1 through 5 (of 5 total)
  • Not sure what you are trying to do with the target so please provide an example of an a href link with what you want.

    But here’s something you can play with:

    <?php
    $cat_id = get_cat_ID('uncategorized'); //<--your category here
    $args=array(
      'cat' => $cat_id,
      'meta_key'=>'your custom field here',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>"rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter lastdragon

    (@lastdragon)

    Thank you Michael, your code is very close to what I’m after…
    I’ll try to expose the whole issue in order to see exactly what I’m after.
    I have a plugin that works with forms (don’t know if it’s OK to say which one because it’s a payed one) and with the help of it I want visitors to add links to already published posts. Basically I want visitors to add in a box the title or anchor text and in another box a link. Then, I want their data to be converged into hyperlinks which will be appended to the already published post they’re on.

    So in order to do that with my plugin, visitors have to create new posts in a specific category which will be hidden in the front-end. The forms plugin will store in a custom field the post id of the post the visitors submit their info on and with the help of the code you have provided me I want to display the list of submitted links in the initial post.

    Hope I managed to explain what I want to do.

    However, with the code you’ve provided I managed to display these added links, but on all posts. I think I have to add as a differentiation parameter the post id of the post the visitors were on when they added the info, post id which is stored in the custom field.

    The problem is how can I create a loop for the single.php which will call the links by category, and by the value of custom post? This value will be different for every post to which I want visitors to add links.

    Do you think this is achievable?

    Thank you,
    Chris

    It might be possible but not sure I know how to do that.

    You will want to look at Custom Fields and maybe something will become clearer.

    Thread Starter lastdragon

    (@lastdragon)

    OK Michael, thank you again for your help.
    If, by a miracle I get it right, I’ll post the solution here.

    Thread Starter lastdragon

    (@lastdragon)

    By now I haven’t find a solution. Still searching… though I’m not sure if Conditional Tags could be a solution.
    Any suggestions on how could I use conditional tags like is_single()? ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get specific posts as links’ is closed to new replies.