0

I'm stuck on loading page content by id (through a plugin). What I have is the following:

<?php $my_query = new WP_Query('page_id=39'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php the_content(); ?>
<?php endwhile; ?>    

Instead of entering the id "39" though, it needs to come from $user_set_value

I'm able to echo the id like this:

<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'user_set_value', true);
wp_reset_query();
?>    

..but how could I go about echoing $user_set_value into the first snippet so it would get the id on the fly?

Many thanks!

2 Answers 2

0

The values assigned to $user_set_value should be stored somehow in some form, usually an option. You will know how the values and where the values are stored. It is easy then from there

$user_set_value = get_some_saved_option_value();
$args = array(
    'page_id' => $user_set_value
);

$q = new WP_Query( $args );

Just change get_some_saved_option_value() with the actual method to get the value.

0

u tried using:

global $post;    
$postid  = $post->ID;

the $post contains data from the current post or page

EDIT: for more info see codex : http://codex.wordpress.org/Function_Reference/$post.

also i think i may have misunderstood your question, are u after:

<?php 
global $wp_query;
$postid = $wp_query->post->ID;
//  get user value and assign it here
$user_set_value = get_post_meta($postid, 'user_set_value', true);
wp_reset_query();  ?>
// pass user value into query
<?php $my_query = new WP_Query('page_id='.$user_set_value); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php the_content(); ?>
<?php endwhile; ?> 
1
  • Please be a bit more verbose in your answers. It's impossible to understand your answer in it's current form.
    – kaiser
    Jan 25, 2015 at 18:23

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.