Custom Query Issue
-
I’m trying to move forward with moving a bunch of data from outside WordPress into WordPress, and running into some troubles.
I’m trying to use the instructions here, and having some issues. Everything I’ve tried, comes back with no results.
The code below, based on what I’m reading, should give me an outputted list of everything post/page that has a custom field like %test%, which exists in my dev database, but I get no results back.
My WordPress install has table prefixes of wordpress_, so I modified the code in the Codex, but still get nothing.
<?php $querystr = " SELECT wordpress_posts.* FROM $wpdb->posts posts, $wpdb->postmeta postmeta WHERE wordpress_posts.ID = wordpress_postmeta.post_id AND wordpress_postmeta.meta_key = 'tags' AND wordpress_postmeta.meta_value LIKE '%test%' AND wordpress_posts.post_status = 'publish' AND wordpress_posts.post_type = 'post' ORDER BY wordpress_posts.post_date DESC "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($pageposts): ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small> <div class="entry"> <?php the_content('Read the rest of this entry ?'); ?> </div> <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments ?', '1 Comment ?', '% Comments ?'); ?></p> </div> <?php endforeach; ?> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php endif; ?>
Also, would it be possible to do the custom query based off of the page title? ie; AND wordpress_postmeta.meta_value LIKE ‘%whatever my page title is%’ ?
Thanks for any help anyone can offer.
- The topic ‘Custom Query Issue’ is closed to new replies.