Novice@PHP Posted October 12, 2012 Share Posted October 12, 2012 I've made a working query to query Wordpress posts by ID but hit a roadblock. I can't pass the custom field value into the post ID array as that is where I will eneter the values to be used in the array. As seen here: listids being the custom field value. <?php &listids = get_post_meta($post->ID, 'list_array', true); $query_args = array('post_type'=>'post', 'post_status'=>'publish', 'include' => 'echo $listids;', 'orderby' => 'date', 'order' => 'ASC'); $query_posts = get_posts($query_args); $last_query = end($query_posts); foreach ($query_posts as $post) : setup_postdata($post); ?> Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/ Share on other sites More sharing options...
Jessica Posted October 12, 2012 Share Posted October 12, 2012 You are literally telling it to use the string 'echo $listids;'. Single quoted strings do not parse. You shouldn't be storing PHP commands inside a string, anyway. Post the code for get_posts. Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384849 Share on other sites More sharing options...
Novice@PHP Posted October 12, 2012 Author Share Posted October 12, 2012 (edited) The query above queries posts on a page that already has a post. It's basically a query to query posts inside posts. So I need to pass the post IDS into the include array using custom fields. But No idea how to do it other than what I've got below. Thanks <?php /* Template Name Posts: List More Posts */ ?> <?php get_header(); ?> <!-- BEGIN COL LEFT --> <div id="colLeft"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="postItem"> <!-- google_ad_section_start --> <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> <div class="categs"><?php the_category(', ') ?></div> <div class="meta"> <div>Last Edited: <?php the_time('M j, Y') ?></div> <div class="icoAuthor">Expert Author: <?php the_author_link(); ?></div> <div class="icoComments"><?php comments_popup_link('No Comments', '1 Comment ', '% Comments'); ?></div> </div> <?php &listids = get_post_meta($post->ID, 'list_array', true); $query_args = array('post_type'=>'post', 'post_status'=>'publish', 'include' => 'echo $listids;', 'orderby' => 'date', 'order' => 'ASC'); $query_posts = get_posts($query_args); $last_query = end($query_posts); foreach ($query_posts as $post) : setup_postdata($post); ?> <?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '" style="float:left;margin-bottom:35px;"'); ?><h3><?php echo get_post_meta($post->ID, 'list_number', true); ?>. <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3><?php the_excerpt(45); ?><a href="<?php the_permalink(); ?>" class="more">Read More..</a><div style="clear:both;"></div><hr /> <?php endforeach; ?> <span class='st_facebook_hcount' displayText='Facebook'></span> <span class='st_twitter_hcount' displayText='Tweet'></span> <span class='st_pinterest_hcount' displayText='Pinterest'></span> <span class='st_linkedin_hcount' displayText='LinkedIn'></span> <span class='st_sharethis_hcount' displayText='ShareThis'></span><br /> <?php the_tags('<p class="tags">Tags: ', ', ', '</p>'); ?> <div id="howback">IGNORE THIS</div> <?php comments_template(); ?> <?php endwhile; ?> <?php else : ?> <p>Sorry, but you are looking for something that isn't here.</p> <?php endif; ?> </div> <!-- END COL LEFT --> <?php get_sidebar(); ?> <?php get_footer(); ?> Edited October 12, 2012 by Novice@PHP Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384857 Share on other sites More sharing options...
Jessica Posted October 12, 2012 Share Posted October 12, 2012 I'm moving this to third party apps. Did you write the get_posts function? I assume not, that sounds like a basic WP function. You probably just want to pass it the array, not a string of php code trying to echo an array. Which wouldn't even be valid PHP anyway. Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384858 Share on other sites More sharing options...
Novice@PHP Posted October 12, 2012 Author Share Posted October 12, 2012 I'm moving this to third party apps. Did you write the get_posts function? I assume not, that sounds like a basic WP function. You probably just want to pass it the array, not a string of php code trying to echo an array. Which wouldn't even be valid PHP anyway. I'm trying to put the value of the custom field into the array 'include' which is a series of post IDs. The biggest issue is I didn't make all of the query, just some of it. The Post IDs part I made but need those IDs to be passed from a custom field. Thanks for your help, hopefully someone can help. Other than that is there somewhere where I can pay for quick help with small snippets like this? I don't like to be a vampire. Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384859 Share on other sites More sharing options...
Jessica Posted October 12, 2012 Share Posted October 12, 2012 We have a freelance forum. Why don't you try what I said though? Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384861 Share on other sites More sharing options...
Novice@PHP Posted October 12, 2012 Author Share Posted October 12, 2012 I don't know what you mean. I tried just putting $listids without the echo and it didn't work. is it fast turnaround and able to deal with small snippets like this? We have a freelance forum. Why don't you try what I said though? Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384884 Share on other sites More sharing options...
Jessica Posted October 12, 2012 Share Posted October 12, 2012 Post what you tried. I don't know, I've never hired someone through it. You asked if there was somewhere you could pay for help. There is. Quote Link to comment https://forums.phpfreaks.com/topic/269398-passing-custom-field-into-wordpress-query_posts-array/#findComment-1384885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.