Sizukhan
Forum Replies Created
-
Forum: Hacks
In reply to: Show Search Results from EITHER Content/Titles OR TagsI did! However, it’s been a few months since I looked at the code, so what I’m about to post may or may not be enough to get it working for you.
So basically, after I finish adding variables and such to $querystr, I have these lines:
$pageposts = $wpdb->get_results($querystr, OBJECT_K); //put the query results into the $pageposts variable $wp_query->found_posts = count($pageposts); //set the number of found posts $wp_query->max_num_pages = ceil($wp_query->found_posts/$resultsPerPage); //calculate the number of pages needed to display all of the reults based on the number of pulled posts and the $resultsPerPage $on_page = intval(get_query_var('paged')); //get the current page number //if, for some reason, the $on_page variable = 0 (which it should NEVER be), reset the varaible to page 1 if($on_page==0) { $on_page=1; } $offset = ($on_page-1)*$resultsPerPage; //calculate the offset (where the page will start displaying posts in the returned array $querystr .= "LIMIT $resultsPerPage OFFSET $offset"; //add the LIMIT and OFFSET parameters to the SQL query $pageposts = $wpdb->get_results($querystr, OBJECT_K); //query again with the newly added LIMIT and OFFSET parameters
Then I have the foreach loop that sets up the CSS and whatever else for each result returned:
//format each displayed result foreach ($pageposts as $post): setup_postdata($post); //...setting up CSS and stuff... endforeach;
And, finally, I have code for the paginated links that appear at the bottom of the page:
$big = 999999999; // need an unlikely integer $pageNumber = (get_query_var('paged')) ? get_query_var('paged') : 1; echo '<div>' . paginate_links( array('base' => str_replace( $big, '%#%', get_pagenum_link( $big )), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged')),'total' => $wp_query->max_num_pages, 'end_size'=>2, 'mid_size'=>2, 'prev_text'=>'<', 'next_text'=>'>')) . '</div>';
And that’s it (I think)! Let me know if that helps ??
Forum: Hacks
In reply to: Show Search Results from EITHER Content/Titles OR TagsOkay, well I think I have it working with MySQL, but now I need help paginating the results. I have:
$querystr=" SELECT * FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms WHERE ($wpdb->terms.name = '$s' OR $wpdb->posts.post_content LIKE '%$s%' OR $wpdb->posts.post_title LIKE '%$s%') AND $wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id ORDER BY $wpdb->posts.post_date DESC "; $pageposts = $wpdb->get_results($querystr, OBJECT_K); foreach ($pageposts as $post): setup_postdata($post); echo the_title() . '<br /><br />'; endforeach;
So (unless I’m missing something), this prints the titles of any posts that have the search term(s) in their tags, titles, or contents!
But again, the problem now is that I have no idea how to paginate my results…
Also (I’m new to pretty much all of this), is this code creating anything in the database that needs to be deleted? Like am I (unknowingly to me with my limited knowledge on the subject) creating extra tables or something that permanently take up space on the database?
Any help would be greatly appreciated!