php - Wordpress query - foreach / while -


I have an index file in a Wordpress template, which shows some blog posts, the query is not there (but I think That it can be overwritten), but blogposts are shown through are_posts (), while loop etc.

It also uses some pannagation.

I have to solve the blog posts based on the meta key related to the author of the post. I have found a solution to do this with

  $ querystr = "select wposts. $ Wpdb-> sending posts, $ wpdb-> usermeta umeta where wposts.post_author = umeta . User_id and umeta.meta_key = 'wp-last-login' and wposts.post_type = 'post' and wposts.post_status = 'publish' order by umeta.meta_value DESC "; $ Pageposts = $ wpdb- & gt; Get_results ($ querystr, object);  

And then make a foreach loop.

It works fine, but it does spoil points on the page.

So I would like to help in finding out how to do it outwardly or to get a way to work with the prediction method or to sort the actual code as above, but the general query- With the method which is used by_post (), time-query etc. Overview of the original code (but without the query) is here.

  & lt ;? Php if (have_posts ()):? & Gt; & Lt ;? Php $ count = 0; While (is_pause ()): the_post (); $ Count ++; ? & Gt; & Lt ;! - Show posts - & gt; & Lt ;? Php timeline; ? & Gt; & Lt ;? Php $ next_page = get_next_posts_link (__ ('next', 'dastro')); $ Prev_pages = get_previous_posts_link (__ ('back', 'destro')); If ((empty! $ Next_page) ||! Empty ($ prev_pages)):? & Gt; & Lt; Div class = "endorsement" & gt; & Lt ;? Php if (! Function_exists ('wp_pagenavi')):? & Gt; & Lt; Div class = "AL" & gt; & Lt ;? Php echo $ prev_pages; ? & Gt; & Lt; / Div & gt; & Lt; Div class = "ar" & gt; & Lt ;? Php echo $ next_page; ? & Gt; & Lt; / Div & gt; & Lt ;? Php Other: wp_pagenavi (); end if; ? & Gt; & Lt; / Div & gt; & Lt ;! - / endorsement - & gt; & Lt ;? Php endif; ? & Gt; Etc ...  

---- Edit -----

I have tried to do this now, but it does not seem to work Happen. It already has_poses () and the loop starts

 Include  in the function Postmeta ($ join) {global $ wp_query, $ wpdb; Join $. = "Join left $ wpdb-> $ wpdb-> posts.post_author = umeta.user_id on USMeta umeta"; Join Refund $; } Function where postmata ($ where) {global $ wp_query, $ wpdb; $ Where = "AND umeta.meta_key = 'wp-last-login'"; Return Where $; } Order Order by PostMeta ($ Order ByeStatement) {global $ wp_query, $ wpdb; $ Orderby_statement = "Umeta.meta_value DESC '"; $ Orderby_statement return; } Add_filter ('posts_join', 'joinPostmeta'); Add_filter ('posts_where', 'wherePostmeta'); Add_filter ('posts_orderby', 'orderbyPostmeta'); To use WP_Query like a normal WordPress loop, you should stick to it, but, it filters the filter that generates the query, so the user asks a question against the metadata as if you ask in your query. 

This will allow WP_Query to implement its normal PageRank rules and other behaviors.


Comments