• I want to do a post query of post type ‘page’ and a custom meta field called ‘related_category’.

    The query appears on the taxonomy page and what it’s supposed to do is load the content of a page that is related to the current term. The idea is that the related page acts as a description for the current term allowing the client to edit this content the same as they would a regular page.

    Basically what I need to do is set the ‘value’ to be $thisTerm. Calling the value as a variable is the part that’s not working for me, if I set the value to a number, it works just fine.

    I’m hoping this is just a simple syntax error, that maybe there’s something different I should be doing in the array when calling a variable.

    <?php
                            $thisTerm = $term->term_id;
                        ?>
                    <div id="courses_content_column" class="span8">
                        <?php
                            query_posts(array('post_type'=>'page',
                                        'meta_query' => array(
                                                        array ('key' => 'related_category',
                                                                'value' => $thisTerm
                                                                ),
                                                            ),
                                                    ));
                        ?>
Viewing 1 replies (of 1 total)
  • As far as I can see, your code is correct. To verify that it is, set $thisTerm to a number and see if it works.

    $thisTerm = 44; // Substitute your actual term_id

    If that works, then more than likely $term->term_id is not returning what you think it should.

Viewing 1 replies (of 1 total)

The topic ‘custom meta_query using a variable for the value’ is closed to new replies.