• Resolved pmdci

    (@pmdci)


    Hi there,

    Got a peculiar request today which I have no idea on how to start! Basically, what I was asked to do is the following:

    When viewing a post (which is information about a hotel), there should be a button/link/whatever that says “show contact details”

    When the user clicks on this button, a pop-up will appear, showing the contact details (which are custom fields) for that hotel.

    With my limited knowledge, I think the way to do this is to have a contact-info.php template, which can accept queries such as: contact-information.php?hotel=sheraton.

    What the customer is trying to achieve is to be able to see in Google Analytics when visitors click on the button/link to see the contact information.

    Is such thing possible? For me this is a firt…

    Any advice is greatly appreciated.

    Cheers,
    P.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pmdci

    (@pmdci)

    Here is the code I made so far. If I load contact-info.php it shows me all the custom of telephones and emails for all my posts (Hotels). But if I try to use contact-info.php?name=<hotel-name> query argument in the URL, it simply ignores it (still shows all posts)… What am I doing wrong?

    If I hard code a hotel name in the query_posts() function, then it shows the data for that particular.

    <?php
    require( '../../../wp-load.php' );
    global $query_string;
    $paged = get_query_var("paged");
    $url = $_SERVER['REQUEST_URI'];
    parse_str($url, $query);
    query_posts($query_string . "&name=" . $query['name'] . "&paged=" . $paged);
    global $more;
    $more = 0;
    ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <caption>CONTACT INFO</caption>
     <tr>
    	<td style="text-align:center"><span><?php echo get_post_meta($post->ID, 'telephone_hotel', true); ?></span></td>
     </tr>
     <tr>
    	<td style="text-align:center"><span><?php echo get_post_meta($post->ID, 'email_hotel', true); ?></span></td>
     <tr>
    </table>
    <div class="dhr-bot"></div>
    
    <?php
    // This is a test, and so far it returns nothing. Why is that?
    echo $query['name']; ?> 
    
    	<?php endwhile; else: ?>
    
    		<div><h3>Not Found</h3></div>
    
      <?php endif; ?>
      <?php wp_reset_query(); ?>

    Any ideas?

    Cheers,
    P.

    Thread Starter pmdci

    (@pmdci)

    Uff… I actually came to this point:

    <?php
    require( '../../../wp-load.php' );
    global $query_string;
    $url = $_SERVER['REQUEST_URI'];
    parse_str($url, $query);
    query_posts($query_string . '&post_type=post&name=' . $query['name']);
    ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php echo $query['name']; ?><br />
    <?php echo $query['test']; ?>

    Basically my retarded code ignores the first query of the URL for some reason (that is, the one with the question mark), but it does accept what is followed by the ampersand. For example:

    contact-info?name=Sheraton&test=hello

    This would return all the posts, with the echo “hello” on the top of each of them.

    contact-info?test=hello&name=Sheraton
    This would then return only the post with the slugname “Sheraton” (which is what I am trying to do this whole time). However, it should also return an echo of $test with the value “hello”, but it doesn’t. So this proves to me that the first URL query, for some reason I don’t know, if being disregarded.

    Any ideas why? I’m stuck on this one… ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show custom fields from a post in a pop-up’ is closed to new replies.