0

I was tasked with rebuilding works website as my first project for the job, and decided to go down the wpalchemy class route to help make meta boxes for my custom post type (I'm not going to use plugins).

I'm currently using (inside my theme page)

    $sidebar_excerpt = $sidebar_excerpt_meta->the_meta();

to make a variable for the meta data and then using

    if ($sidebar_excerpt) {
        echo '<img src="'.$sidebar_excerpt['sidebar_img_url'].'" />';
        echo '<p>'.$sidebar_excerpt['description'].'</p>';
    }

To check that the data exists before displaying it, although I have a dilemma! I want to actually display not just meta data from this particular page, but loop over all the database data for this particular metabox, does that make sense?

So each of my custom post type pages has 1 excerpt description and text, then overall on the actual template page I want to grab ALL the excerpt data from all pages from the content post type with this metabox data, then I'll limit the output to 3 or so.

I really want to achieve this although I'm scared I'll go over my deadline without working this one out? could any kind person please advise me or point me on the right track?

Many thanks Phil

2 Answers 2

0

Phil, you will have to use the Loop and loop over all the posts from the post type you want, then with wpalchemy you can do the following (using the post ID):

$sidebar_excerpt = $sidebar_excerpt_meta->the_meta( $post_ID );

See also: http://codex.wordpress.org/The_Loop

0
0

Farinspace, thanks for your reply, I thought it'd be slim that you'd spot this but thank you very much.

I kinda tried what you said before posting my OP, although ...oddly it doesn't seem to work unless I use get_post_meta.

$sidebar_excerpt = $sidebar_excerpt_meta->the_meta( $post_ID );


$loop = new WP_Query( array( 'post_type' => 'services_cpt' ) );

    while ( $loop->have_posts() ) : $loop->the_post();
        if ($sidebar_excerpt){
            // This doesn't work
            echo '<p>'.$sidebar_excerpt['AFI_excerpt'].'</p>';

            // This works
            echo '<p>'.get_post_meta($post->ID, 'AFI_excerpt', true).'</p>';
        }
    endwhile;

See my commented code, thanks.

EDIT:

I put

$sidebar_excerpt = $sidebar_excerpt_meta->the_meta( $post_ID );

Inside my while loop, and turned off WPALCHEMY_MODE_EXTRACT and got it working, what's the deal, why doesn't it work with this mode? :S!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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