• Resolved Marc

    (@standoutt)


    I hope this isn’t complicated, but here is what I’m trying to achieve.

    I have a custom field that image addresses are normally entered into. What I want to do is call the 4 latest values and have those four images displayed in a row. Each image needs to link to the post it came from.

Viewing 15 replies - 1 through 15 (of 17 total)
  • MichaelH

    (@michaelh)

    One option is to use something like

    $your_cusom_field_key = 'image';
    $posts=query_posts('meta_key='.$your_cusom_field_key.'&showposts=4');

    And then look at some examples of using those Custom Fields in this article:

    https://justintadlock.com/archives/2007/10/27/wordpress-custom-fields-adding-images-to-posts

    Thread Starter Marc

    (@standoutt)

    It doesn’t seem to be doing anything. This is what I inserted into the template:

    <?php $your_cusom_field_key = 'MoviePoster';
    $posts=query_posts('meta_key='.$your_cusom_field_key.'&showposts=4'); ?>

    I forgot to mention that this needs to be on a page and not in a post. I’m not sure if that changes anything or if I’m just doing something wrong.

    gbaka

    (@gbaka)

    all you have to do is place that code in a type of word file and rename it to a php file and upload it then go new page put a title and select the php file from the sidebar and the code should work if u can show me the site i might have a idea of whats going wrong.

    Something like this? All the information you see comes from custom fields.

    I’ve described it here.

    Peter

    Thread Starter Marc

    (@standoutt)

    @gbaka Here’s the page: https://www.srizzil.com/movies/ The code should be on line 170 but doesn’t appear at all when looking at the source of the page. There must be code missing.

    @pboosten What you’ve done is very similar to what I want to achieve but trying to modify your code continually gives me syntax errors.

    I simply want to pull the poster from the 4 latest reviews and display them on the page. The user then should be able to click on the poster to take them through to the review.

    I don’t have much experience so it’s very likely I’m doing something wrong.

    A collegue of mine told me that you cannot simply copy&paste my code.

    The fault is in the quotes, and the php tags.

    I’ll put both on a site for download:

    page-book-overview.php

    page-book-review.php

    Thread Starter Marc

    (@standoutt)

    Thanks @pboosten. That’s solved the syntax errors but now it’s doing the same thing as the other code. It’s just not there when the page renders. If you look at the source code for the above link your code should be on line 177.

    Hmmm, I gotta feeling you don’t understand the concept of php: it’s the webserver translating that into something that can be read by the browser.

    The result is never source code, but xhtml.

    I do some queries through the posts, I presume you have some code above mine, right?

    In that case you need to reset the query just before you start ‘mine’ with wp_reset_query();.

    Peter

    Thread Starter Marc

    (@standoutt)

    I think I understand that concept, but surely there should be some xhtml on that line from the code. At this point there is nothing.

    I do, here’s what I tried to no avail:

    <TD VALIGN="TOP" width="800" BG="#ffffff">
    <?php wp_reset_query(); ?>
    <?php if ( (is_page('Movies')) ){
    
    			query_posts(array('showposts' => 8, 'post_parent' => 949, 'post_type' => 'page'));
    
    		  while (have_posts()) {
    
    				the_post(); // vital
    
    				$thumbPath = get_post_meta($post->ID, 'MoviePoster', true);
    
    				$thumbPath = "" . $thumbPath;
    		?>
    
    				<a href="<?php the_permalink(); ?>" class="grid-book">
    					<img src="<?php echo $thumbPath ?>" alt="" /><br />
    					<span class="grid-title"><?php the_title(); ?></span><br />
    				</a>
    
    			<?php }
    
    		}
    		?>
    
    </td></tr></tbody></table>

    The td tag should be lower case, but that’s not the issue.

    Just to be sure: you’re searching for the Custom Field ‘MoviePoster’ in the first 8 pages (not posts), which are subpages of page ID 949 that you encounter?

    Peter

    Thread Starter Marc

    (@standoutt)

    The reviews are posts. However this is being displayed on a page. I want the 8 latest reviews to have their posters show up and link to that particular post from this page.

    Then you need to change your query:

    query_posts(array('showposts' => 8, 'post_parent' => 949, 'post_type' => 'page'));

    this query searches for 8 sub pages of post 949.

    try this:

    query_posts(array('showposts' => 8, 'post_type' => 'post'));

    Peter

    Thread Starter Marc

    (@standoutt)

    Yes! Thank-you! Thank-you! Thank-you!

    That’s exactly what I need. You’re a genius!

    nah, I just wanted to prove that the code in my article worked ??

    Peter

    Thread Starter Marc

    (@standoutt)

    All I need now is to limit it to a certain category.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Calling Custom Field values for specific key.’ is closed to new replies.