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'm pulling custom posts by their meta_key using this function:

<?php $args = array(
    'numberposts'     => 10,
    'meta_key'        => 'allvotes',
    'orderby'         => 'meta_value',
    'order'           => 'DESC',
    'post_type'       => 'things',
    'post_status'     => 'publish' );
$mystuff = get_posts( $args );
?> 

I want to involve a form which will edit my variables, but when I try my code, it doesn't return any posts...

<?php
 $filter = $_POST['country'];
 $submit = $_POST['submit'];
 if(isset($submit)){
    $args = array(
    'numberposts'     => 10,
    'meta_key'        => '$filter',
    'orderby'         => 'meta_value',
    'order'           => 'DESC',
    'post_type'       => 'things',
    'post_status'     => 'publish' );
$mystuff = get_posts( $args );
$name = $filter ;
}
else {
    $args = array(
    'numberposts'     => 10,
    'meta_key'        => 'canada',
    'orderby'         => 'meta_value',
    'order'           => 'DESC',
    'post_type'       => 'things',
    'post_status'     => 'publish' );
$mystuff = get_posts( $args );
$name = 'Everywhere';
};
?>
share|improve this question
add comment

closed as too localized by anu, toscho Jul 18 '12 at 19:02

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 2 down vote accepted

Don't put your variables in single quotes.

This:

if(isset($submit)){
    $args = array(
        'numberposts'     => 10,
        'meta_key'        => '$filter',
        'orderby'         => 'meta_value',
        'order'           => 'DESC',
        'post_type'       => 'things',
        'post_status'     => 'publish' );
    $mystuff = get_posts( $args );
    $name = $filter ;
}

Should be this:

if(isset($submit)){
    $args = array(
        'numberposts'     => 10,
        'meta_key'        => $filter,
        'orderby'         => 'meta_value',
        'order'           => 'DESC',
        'post_type'       => 'things',
        'post_status'     => 'publish' );
    $mystuff = get_posts( $args );
    $name = $filter ;
}
share|improve this answer
    
ah! I'm stupid. thanks haha –  marctain Jul 18 '12 at 15:58
add comment

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