-1

I have a form in the sidebar on the following WP site — http://www.mattpealing-server.co.uk/~devchewengco/

Here is part of the code I'm using for the results page:

<?php if (isset($_GET['ApplianceType']) || isset($_GET['brand'])) : // search filter form ?>
    <?php query_posts($query_string . '&orderby=title&order=ASC') ?>
        <?php get_template_part('loop', 'feed-products' ); ?>
    <?php wp_reset_query(); ?>

<?php else : // display categories as default ?>
    <?php get_template_part('include', 'feed-categories-products' ); ?>
<?php endif; ?>

But the statement is always returning false. Originally, I had it without the isset() function, but that was giving me undefined variable errors

Can anyone see what I'm doing wrong?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • 2
    Why your every line contains `` if there is only PHP in code and no other language? – Justinas Nov 10 '14 at 12:10
  • if(condition){ code; } – el3ien Nov 10 '14 at 12:12
  • http://stackoverflow.com/questions/4586835/how-to-pass-extra-variables-in-url-with-wordpress – Steve Nov 10 '14 at 12:16
  • 1
    try echo '
    ';print_r($_GET); echo '
    '; and let us know the result
    – Riad Nov 10 '14 at 12:18
  • @Justinas Have you ever seen what WP files look like? (no idea why they chose that approach though) – Shomz Nov 10 '14 at 12:19
  • @Shomz yes, and what's the difference between WordPress `.php` file and Yii `.php` file (except operations)? If you see wrong code you continue to write code or you try to fix your own code to be good? – Justinas Nov 10 '14 at 12:21
  • 1
    @Riad thanks, I've given that a shot. It tells me it's an empty array –  Nov 10 '14 at 12:22
  • @Justinas I'd always try to follow the existing style (that's WP, a highly established framework, not a plugin from some lame dev in which case I'd consider rewriting), no matter what I think about it. So you'd rewrite all the WP theme files and then when there's an update - BOOM. Here we go again. – Shomz Nov 10 '14 at 12:24
  • @Shomz No, you don't rewrite everything. Only what you have updated. I personally follow PSR-2. Your `BOOM` will be only if you rewrite core of framework. In other case it's safe to change files since they will not be updated. – Justinas Nov 10 '14 at 12:45

2 Answers2

1

Just found that in this URL you have the undefined warning. You have to use:

isset($_GET['Brand'])  // you are using 'brand' 
Riad
  • 3,822
  • 5
  • 28
  • 39
0

You are not necessarily doing something wrong. If you are getting "undefined variable" errors without the isset-checks, it probably means the ApplianceType and brand key in the $_GET array are undefined.

They are either removed or simply not set.

Elias
  • 1,532
  • 8
  • 19