-2

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';
};
?>

closed as too localized by anu, fuxia 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.

2

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 ;
}

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