• I am needing to display posts in a particular order and have the mysql query returning results as needed however, I cannot seem to figure out where I need to add the code in. I would like to have 3 different custom queries depending on a variable passed to the index.php page, say sort=1, sort=2, and sort=3. Where do I place the add_filter calls and functions they add for joins, where, and orderby? I cant seem to find where the get_posts method is called in the process of a page loading. Any help is greatly appreciated!!!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Exactly where the code is placed depends entirely on your theme. If you are using a free theme, post a link to your site here and someone may be able to help. If you are using a paid theme, contact the theme supplier.

    Thread Starter blk784

    (@blk784)

    I ended up placing the code in the functions.php file in the theme folder I am using. Now my problem is that the search filters are causing other pages to not show up. I want to somehow set a flag if it is the home page so that the filters are added (if(is_home()) do->this) but the is_home and is_front_page functions don’t seem to be working in that functions.php file. I would like a get variable to be populated when the homepage is loaded and if it is set then I know to add the filters. Where can I put code to set a get variable on home page load?

    One solution I have used to turn a filter on and off is to use a global variable.

    I set the global variable just before issuing the query that I want filtered and then clear it just after the query.

    I check for the global variable in the filter function and only filter if it is set.

    Thread Starter blk784

    (@blk784)

    I have a problem with the filters I have applied interfering with other pages not being found and also when logged in to the admin panel viewing all posts only gives me the posts that the custom query I have set up returns. How can I only apply the filters for the custom query for the homepage and homepage only and not all other areas of the site?

    One solution I have used to turn a filter on and off is to use a global variable.

    I set the global variable just before issuing the query that I want filtered and then clear it just after the query.

    I check for the global variable in the filter function and only filter if it is set.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Query’ is closed to new replies.