Jump to content


Photo
- - - - -

Custom Wp_Query


Best Answer jbrouwer , 06 December 2012 - 11:00 AM

Well. The above code does work (incl. pagination) with the GET method! Are there any security issues with using GET? I guess it is fine to use for a filter?

 

Thanks!

Go to the full post


  • This topic is locked This topic is locked
23 replies to this topic

#1 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 03 December 2012 - 01:39 PM

Hi,

 

I would like to do a custom query. I have added a custom query in the postloop section (which I copy-pasted in a child theme):

 

Please Login or Register to see this Hidden Content

 

 

It is working. However, pagination is not working properly. I understand from different forums that I should use wp_query. My question is how I can use wp_query within Pagelines. I have tried:

 

Please Login or Register to see this Hidden Content

 

but I don't know how I can execute this new query in Pagelines. 

 

Thank you.



#2 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 03 December 2012 - 02:21 PM

Google search pre_get_posts filter
  • jbrouwer likes this

#3 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 03 December 2012 - 03:10 PM

I am not sure, but I think I cannot use this filter as I want to make a frontend filter for users (i.e. a buttons to sort by rating, date etc). Or is it possible to execute the filter only after a button is submitted?



#4 beardedavenger

beardedavenger

    Unicorn Wrangler

  • Members

  • 1219 posts
  • Country: Country Flag

Posted 03 December 2012 - 03:46 PM

You don't need a filter. Paged results is kind of a bitch to get working correctly within PageLines. There's a default section called Pagination that will work with your query in your section. Just drag the Post/Page Pagination section below your new section.



#5 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 03 December 2012 - 04:20 PM

I already was using the Post/Page Pagination section below the new section, hence that's not it. 

 

I understand the pre_get_posts filter is the best solution as it runs (as it's name suggest) before the first query and prevents unnecessary requests, but I don't know how to execute it out of a form action. Any ideas?

 

An alternative could be to use wp_query. Any ideas how I can use a custom wp_query within Pagelines?



#6 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 03 December 2012 - 05:56 PM

I tried this:

 

Please Login or Register to see this Hidden Content

 

Stil no luck with pagination....



#7 beardedavenger

beardedavenger

    Unicorn Wrangler

  • Members

  • 1219 posts
  • Country: Country Flag

Posted 03 December 2012 - 06:30 PM

I just went through all of this as I wrote AnyLoop, a custom post loop section on the store. It has multiple wp_queries and can run simultaneously. And after much frustration, using the section I described works, with wp_query. Feel feel to experiment on your own, I'm just trying to save you some time.



#8 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 03 December 2012 - 06:52 PM

That is very much appreciated. 

 

How can I execute a wp_query in Pagelines?



#9 beardedavenger

beardedavenger

    Unicorn Wrangler

  • Members

  • 1219 posts
  • Country: Country Flag

Posted 03 December 2012 - 08:20 PM

Just create your own section using the Base Section (known as the free Pull Quote example section in wp admin store), drop in the query, and fashion the output how you please. Then just drop the section on whatever you page you want.



#10 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 04 December 2012 - 07:45 AM

Do you mean I have to build and style my own loop? I was hoping I could create a custom wp_query and use the Pagelines loop. Is that possible?



#11 Danny

Danny

    Is Awesome!

  • Moderators
  • 17015 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 04 December 2012 - 08:35 AM

Hi,

 

PHP at the moment is my forte but this topic should help you.

 

Please Login or Register to see this Hidden Content



#12 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 04 December 2012 - 12:25 PM

Thanks. I see I was struggeling with this already in december :-)

I have this working with post_query. Created a custom section in the base child theme. This works:

 

Please Login or Register to see this Hidden Content

 

I can change the array of the query_post to get any custom loop I would like. However, using query_posts gives trouble with the pagination. I read on a couple of forums that I should use wp_query. Let's say I would like to query only cat 3. Wordpress codex shows this code:

Please Login or Register to see this Hidden Content

Adding this in a custom section also works great. It creates a list of category 3 post titles. Instead of this simple loop I would like to load the Pagelines loop. How can I do that? I tried 

 

Please Login or Register to see this Hidden Content

 

but that didn't work.

 

Thanks!



#13 Danny

Danny

    Is Awesome!

  • Moderators
  • 17015 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 04 December 2012 - 12:48 PM

Hmm, it would appear that the code on the link I gave you has been stripped, let me find this out for you.



#14 beardedavenger

beardedavenger

    Unicorn Wrangler

  • Members

  • 1219 posts
  • Country: Country Flag

Posted 04 December 2012 - 02:40 PM

Use WP Query to run a new query.



#15 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 04 December 2012 - 03:39 PM

@beardedavenger could you give me an example please?



#16 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 05 December 2012 - 08:48 AM

I cannot imagine this is hard for a pagelines developer :) Pretty basic customization stuff I would say. It would be very much appreciated if someone could give an example of how I can do a custom wp_query in Pagelines while using the Pagelines loop. 



#17 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 05 December 2012 - 02:30 PM

Please Login or Register to see this Hidden Content

 

That adds your rating, but you need to add a check in there for 'if a button is pressed'



#18 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 06 December 2012 - 09:46 AM

Hi,

 

Thank you for your time!. Actually I already had the filter working. What I am trying to accomplish is a couple of buttons wihch users can click to sort the posts (based on rating, views and date). I would like to have the filter buttons above all loops and behave dynamic. Hence, when a user is on a category/taconomy/tag page it will filter the posts within that taxonomy. My guess was that I should use a custom wp_query instead of the pre_get_post filter to allow dynamic behaviour? That is why I was looking for an example of a wp_query instead of query_posts within pagelines?

 

In the meantime I could show the buttons only for the mainloop on the homepage. The code below works, but not with pagination... :-) Maybe because the pre_get_posts filter gets the $filter variable to late or something? 

 

Please Login or Register to see this Hidden Content



#19 Danny

Danny

    Is Awesome!

  • Moderators
  • 17015 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 06 December 2012 - 10:57 AM

Hi, I think the best course of action would be to contact one of our Pros regarding this customisation.

Please Login or Register to see this Hidden Content



#20 jbrouwer

jbrouwer

    Super Member

  • Members
  • 191 posts
  • Country: Country Flag

Posted 06 December 2012 - 11:00 AM   Best Answer

Well. The above code does work (incl. pagination) with the GET method! Are there any security issues with using GET? I guess it is fine to use for a filter?

 

Thanks!