Articles of wp query

Accessing GET variable named 'error'

As part of a project I’m required to make a wordpress plugin which integrates with Google for authentication (There are good reasons for developing a new plugin instead of using an existing one). If the user decides to cancel the login during the authorisation process then google will redirect back to my site and will […]

post_per_page ignored in WP_Query

I have a custom post type named ‘album’ and I added two custom fields ‘release_date’ and ‘release_date_us’ with the ACF plugin. I’m trying to display the latest albums based in a widget area. The number of albums to show is set with my widget. Here is the query I use in my widget : <?php […]

Displaying a div from an assigned meta_value when on a page

On my website I created a custom metabox that is being displayed in the post type “page”. The metabox will display a checkbox and 4 url fields. The checkbox will control the visibility of a div (section#footerLinks) and the url fields will control the 4 links that will appear with the div links. Ability The […]

ACF accessing a field from the query, but not in post

I’m not sure if this is possible – but checking before re-writing the template. I’ve extended wp_query to allow for a geocode/location search to be performed. This is working in itself and returning posts in a nearest to search point first order. In the query generated now by wp_query it’s calculating the distance in miles […]

Custom taxonomy wp_query woes.

Here’s a brief outline of the set-up: “The Art” CPT is where all the art and art descriptions are uploaded. In this CPT you can choose the category (custom taxonomy) of the art–painting, jewelry, sculpture, etc. This allows me to have a page that displays all the art that’s filterable with Isotope. I’m also sharing […]

What is the best way (regarding performance) to set transients for logged in users?

I have an option for my logged in users where they can hide the posts they dont want to see. Everything works as expected until I implement transients. When I set the transients to cache the posts queries, the posts are not hidden until the transients expire. So, what should I do? The only thing […]

Filtering WP_Query result by category

Using WP_Query, I need to gather a selection of posts that are both Category1 and Category2. I want this selection to include Category1 and all of its subcategories (Category3 and Category4), as long as they are also labeled Category2, even if they aren’t labeled Category1. Categories: Name ID Parent Category1 1 Category2 2 Category3 3 […]

Orderby custom meta returns random order

[Answered by Roberthue – I was sorting by meta_value instead of meta_value_num] I’ve created a WP_Query that does the following: Grabs a list of businesses for sale Orders them by a meta query, taken from the URL using get_query_var Uses a sort order from the query var Checks a meta_query to ensure the sale item […]

List of ways to access WordPress database?

I’m trying to get a complete understanding of how WordPress works with databases. I’ve read the documentation but I’m getting confused by all the different approaches available. So far my understanding is this (layered by level of abstraction from the database): ========================= “WP_API” (for REST/HTTP data access) ========================= “get/add/update/delete” functions (e.g., get_post_meta()) ========================= “WP_Query” class […]

Every second post different class in blog view

To assign different classes to every 2nd post in blog view in WordPress adding this code into function.php was suggested as solution. Most people claim it is helpful, but to me it just adds odd at the end of the post class. There is no even class anywhere. function alternating_post_class($classes) { global $wp_query; $classes[] = […]