Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to display custom fields on my template values of which i am pulling from postmeta table doing something wrong with a loop or not writing the foreach args correctly not sure whats the problem pastebin link for the code http://pastebin.com/eyPD6Qws

basically i want to display 15 div's with 3 cols so to say (name, photo,region)

To make it more simple to explain exactly what i am doing is using a plugin called flutter(yes i know it is dead now) but it works for me i am creating profiles for say agents there individual pages work perfectly but now i want to create a page where i display small brief of everyone's profile (like we have portfolio pages) for which i have created a code(which can be seen here http://pastebin.com/eyPD6Qws)

share|improve this question
add comment

3 Answers

Technically, you should use WP's built-in class WP_Query to pull the information and I am sure that will alone simplify your entire process.

share|improve this answer
    
Puneet, i am not much of a php coder, if you can explain a bit looking at my pastebin code i have added up, would be of much help thanks –  robin Aug 30 '12 at 1:23
add comment

Use a simple loop. Inside the loop and call the meta data with the basic template function get_post_custom().

// Short'n'dirty...
if ( have_posts() ) : while ( have_posts() ) : the_post();

    $meta = get_post_custom( get_the_ID() );

    echo "\n<hr />{$GLOBALS['post']->post_title} Custom Data:\n<pre>".var_export( $meta, true ).'</pre>';

endwhile; endif;
share|improve this answer
    
na it gives an error and could you explain how is it exactly pulling the 3 values i need to display –  robin Aug 30 '12 at 1:23
    
Ehm... "gives an error" is like saying "the sky got a color" - it doesn't help determining what the problem is. Please add a full error output + description. Further: Have you checked wher "Flutter" saves the post meta data - maybe you are wrong with postmeta table? Also: You're talking about profile data. Are you sure, that we're not talking about user meta data? –  kaiser Aug 30 '12 at 1:49
    
Ok so gives an error (page doesnt display at all), yes it works file (my query (Code) which i have written and pulls the content and everything which i want to display) as i stated my problem is the loop, or foreach(args) which i a writing and calling three times for 3 different values i tried using array.combine, and other functions like that but they dont work in my case, (please take a look at the pastebin code i have added in my question) –  robin Aug 30 '12 at 1:57
    
How the result should come box 1 - name1, photo1, region1 box2 - name2,photo2,region2 box3 - name3, photo3,region3 right now after my looping and everything it is coming as box1 - name1,photo1,region1 box2 - name1,photo1,region1 box3 - name1,photo1,region1 i know my data pulling query is right because if i dont and break, or make for loops it displays all the content which i am pulling but not formatted + sort of endless loop –  robin Aug 30 '12 at 2:03
    
The Post title comes three times each? –  kaiser Aug 30 '12 at 3:38
show 4 more comments
up vote 0 down vote accepted

Answer to my problem, finally sorted it (happy-face) {

            global $wpdb;  
        $broker_names = $wpdb->get_results("SELECT meta_value
            FROM $wpdb->postmeta 
            WHERE meta_key = 'B_name'  ORDER BY  meta_id DESC  ", ARRAY_A);  
        $b_region = $wpdb->get_results("SELECT meta_value
            FROM $wpdb->postmeta 
            WHERE meta_key = 'Region' ORDER BY  meta_id DESC ", ARRAY_A);

            $b_photo = $wpdb->get_results("SELECT meta_value
            FROM $wpdb->postmeta 
            WHERE meta_key = 'Photo' ORDER BY  meta_id DESC ", ARRAY_A); 


                for($d=0; $d<=count($b_names); $d++)
                {
                    echo '<div id="b-group"><dl class="b-badge">';
                    echo '<dt class="b-image">';
                    echo '<img src='.get_site_url().'/wp-content/files_flutter/'.$broker_photo[$d]['meta_value'].' /></dt> ';
                    echo '<dd class="b-name"><span>'. $b_names[$d]['meta_value'].'</span>'; 
                    echo '</dd><dd class="b-region">';
                    $r_region = $b_region[$d]['meta_value'];
                    $new_region = unserialize($r_region);
                    echo '  '.$new_region[0].'</dd> ';  
                    echo '</dl></div>';

                }

}

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.