Articles of query

Insert static element only once in query archive

I’m looking to insert a foreign div-element only once in a archive query on my page. So that for example: Post1 Post2 [Static Div] Post4 Post5 …etc My query is: <?php $archive_args = array( post_type => ‘post’, ‘category_name’ => ‘category’, ‘posts_per_page’=> -1, ‘meta_key’ => ‘number’, ‘order’ => ‘ASC’ ); $archive_query = new WP_Query( $archive_args );?> […]

How does WordPress determine if a paged query var is too high?

Inspecting the rewrite rules for author archives I can see that any digit used after page/ is matched. author/([^/]+)/page/?([0-9]{1,})/?$ => index.php?author_name=$matches[1]&paged=$matches[2] In theory, this means the following pages are possible author/username/page/262/ author/username/page/26278/ author/username/page/26278292/ In real life if you visit these pages you’ll get a 404 (unless the author has been crazy busy posting). How does […]

Echo a hierarchical list of post data from custom fields

I have a custom post type ‘locations’, with custom fields ‘State’, ‘City’, ‘Address’, and ‘Phone’. I would like to query these fields in an organized list. Let’s say I have these three posts: City: Los Angeles; State: California; Address: 123 Main St.; Phone: 888-111-2222 City: San Jose; State: California; Address: 55 1st St.; Phone: 888-333-4444 […]

only delete post within query / for each statement (front end)

I am using this in my functions which I can use to delete the current page (custom post type called – bucket) and all it’s children: function delete_post(){ global $post; $deletepostlink= add_query_arg( ‘frontend’, ‘true’, get_delete_post_link( get_the_ID() ) ); if (current_user_can(‘edit_post’, $post->ID)) { echo ‘<span><a class=”post-delete-link” onclick=”return confirm(\’Are you sure to delete?\’)” href=”‘ . $deletepostlink . […]

How can I get the query that would be run for the archive page?

When a user visits a post type archive page on my site, I’ve got a bunch of hooks and filters that run on that query and get it just so. How can I, in a different request, say “I want the query that would run when I go to /archives” so I can get those […]

Overriding default calendar to show posts from a category

I’m trying to modify the default WP calendar (get_calendar()) so that it shows posts from a specific category and then use that as a shortcode. Here’s what I’ve done: Copied across the get_calendar() function from the core (from wp-includes) into my child theme’s functions.php file. In order to make it an ‘independent’ calendar, I changed […]

Disallow categories from this MySQL query

I’m trying to modify a plugin that generates an archive listing so it shows only one category, making it a single category archive. The old version of the plugin used a get_posts query, and so it was easy to disallow categories of posts: $rawposts = get_posts( ‘numberposts=-1&category=-4,-6,-7,-9’ ); The new version of the plugin uses […]

Count how many posts have a custom field set

I’ve added some code to my templates which automatically adds custom fields to cache some data that each post pulls in. Is there a way that I can track how many posts have had this custom field set?

Huge amount of queries on my site

My site is reaching CPU limits all the time, I just ran Debug Queries and got more than 4000 queries, no wonder site is slow.

Query all posts which do not have tags assigned to them

Is there a way to query posts which do not have tags assigned to them? query_posts(‘tag=’tag_exmaple’&posts_per_page=-1’); Ty very much!