Forums

get 2 posts inside another? (or any better ideas) (8 posts)

  1. waylow
    Member
    Posted 2 years ago #

    Hello all,

    I'm new <insert newbie apology here>

    I run a weekly comedy night and am trying to set up a WP website to do so

    here is the situation:
    Every week we advertise 2 comedians on the website (1 MC and 1 Feature)
    there are over 200 comedians in our database
    I plan to set up each comic as a 'post', and then use a gig calendar to display these 'posts' on the correct calendar date
    (each comedian may appear more than once a year as either the MC or Feature)

    I have tried several ways to do this with varying degrees of success
    at the moment I am using the "event calendar 3" plug-in for the calendar part, which creates a "post" and then I try to call the 2 relevant posts (MC and feature) inside this event post

    if I use the [get-post] plug in - I can only call 1 post (or 2 of the same) and it doesn't get the post formatting

    if I use the <query_posts> with php (I have the exec-php plugin enabled) - the formatting works but I can only call 1 of the required posts

    So my question is:
    How can I call 2 (different) posts inside another?
    or is there a better solution for my problem?

    This is the WIP website, if it helps:
    http://www.amicinhand.com/WP_Sydney/

    any advice is welcomed

  2. Frumph
    Member
    Posted 2 years ago #

    Create new instances of the wp_query so they don't interact with the other ones.

    <?php
    $save_wp_query = $wp_query;
    $save_post = $post;
    
    $comicMC = new WP_Query(); $comicMC->query('showposts=1&cat=#');
    while ($comicMC->have_posts()) : $comicMC->the_post();
    ?>
    Your HTML code here.
    <?php
    endwhile;
    
    $comicfeature = new WP_Query(); $comicfeature->query('showposts=1&cat=#');
    while ($comicfeature->have_posts()) : $comicfeature->the_post();
    ?>
    Your HTML code here.
    <?php
    endwhile;
    
    $post = $save_post;
    $wp_query = $save_wp_query;
    $save_wp_query = null; $save_post = null;
    ?>

    Probably best to make them functions and using shortcode, that would be optimal, but please remember to save the $wp_query and $post then restore them after doing the loops. you might need to do a setup_postdata($post); in the while loop, unsure on that one.

  3. waylow
    Member
    Posted 2 years ago #

    thanks for the help Frumph,

    this is a little bit above my knowledge level at the moment but I know I will get my brain around it.

    I would like to turn this into a short-code function - but only after I get it working
    then I can figure out how to turn it into short-code

    so the code you have written is a loop, right?
    and this loop meant to go inside the "event" post (the one that the event calendar creates)?

    so how do I get this loop to to display the 2 posts I want it to display?
    as in where to I put the name of the MC tag to display the MC
    and where do I put the name of the Feature tag to display the feature
    (I have given each of the comedians posts a unique tag)

    cheers

  4. Frumph
    Member
    Posted 2 years ago #

    See the cat=# that would be the cat=<category the MC or Feature is in> that you said you created for those people.

  5. waylow
    Member
    Posted 2 years ago #

    All the comics have the same cat but I created a unique tag for each comic (so I don't have to have 200 categories)

    If I leave it as cat=# to test - I can see the "Your HTML code here"
    if I change it to a cat that exists - the "Your HTML code" disappears

    and because I want to use tag in place of cat
    I changed it tag=# - I can see the "your HTML"
    I change it to the unique tag - I can't see the "your HTML" bit

    I have also tried this code outside a post (in the index.php file) with the same result

    something isn't working but I'm not sure what it is
    (I have also tried to remove the $comicFeature part of the the code to see if it was interfering)

  6. Frumph
    Member
    Posted 2 years ago #

    Naw, just read the codex on how to use the wp_query to get the in taxonomy tags for a proper query.

  7. waylow
    Member
    Posted 1 year ago #

    cheers, got it working

    thanks for the help.
    (I was doing something stupid on my end)

    any advice on making this a function - where do I start reading?
    (is that turning it into a plug-in?)

  8. Frumph
    Member
    Posted 1 year ago #

    search the codex for 'shortcode' and how to do that, would make a great shortcode.

    even better would make a great new custom post type with taxonomy system in wordpress 3.0

Topic Closed

This topic has been closed to new replies.

About this Topic