Using Custom Select Query and Magic fields
-
Hello, i have this perfectly working code showing posts based on two or more custom fields;
<?php global $wpdb; global $post; $key1 = 'color'; $val1 = 'red'; $key2 = 'shape'; $val2 = 'square'; $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta metacolor, $wpdb->postmeta metawgt WHERE wposts.ID = metacolor.post_id AND wposts.ID = metawgt.post_id AND (metacolor.meta_key = '$key1' AND metacolor.meta_value = '$val1') AND (metawgt.meta_key = '$key2' AND metawgt.meta_value = '$val2') AND wposts.post_type = 'post' AND wposts.post_status = 'publish' ORDER BY UPPER(wposts.post_title) ASC "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($pageposts): ?> <?php global $post; ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <div class="post" id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a> </div> <?php endforeach; ?> <?php endif; ?>
now I installed Magic Fields and it looks like it won’t filter posts with custom fields added over Magic fields,
is there maybe some small editing needed in the code above?
thank you
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Using Custom Select Query and Magic fields’ is closed to new replies.