Jump to content

Recommended Posts

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); ?> 

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 by Novice@PHP

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 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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.