Questions tagged [query]

A generic term referring to the process of retrieving information from a database.

Filter by
Sorted by
Tagged with
2
votes
1answer
501 views

Adding posts of custom type into the main feed

I'm having some trouble with a subject that seems to be pretty basic, so I'm starting to feel (a little, only a little) dumb :-) Here's the thing: I want my main feed to include the posts and other ...
2
votes
1answer
640 views

Sort posts based on multiple custom fields

I have a three custom fields Meta Key → YOUR_PREFIX_newcar_body_type Meta Key → YOUR_PREFIX_newcar_transmission_type Meta Key → YOUR_PREFIX_newcar_variant and I have to sort posts ...
2
votes
3answers
890 views

Wordpress query by category, sorted by custom field

I have three custom fields set for each of the posts in the events category — year, month, and day. I am already querying for the events category, and now I'd like to sort the posts by the custom ...
2
votes
1answer
62 views

Listing posts by grouping dates

I have a music events site http://www.zarpa.eu. I'm using the Future is Now plugin to help me to schedule the events http://wordpress.org/extend/plugins/the-future-is-now/ I'm trying to group ...
2
votes
2answers
7k views

Does meta_query work within get_posts array?

I can't seem to get this to work — I'm trying to show posts that have the meta 'featured_image' value set to anything. From what I can tell, it's set up correctly, but I'm in a little over my head. ...
2
votes
1answer
365 views

mysql query paging

Hi I have made an sql query that gets several posts according the parameters that i've selected. I'm showing these posts but the inner paging within wordpress doesnt do anything. It shows me that ...
2
votes
2answers
114 views

$wpdb->query() vs. $wpdb->get_results() vs. phpMyAdmin

I have this code: $query = "SELECT * FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ...
2
votes
2answers
139 views

Query all posts and not repeat the same tag

I need a query to show all posts in the site but not repeat the ones with same tag, I mean only show one post with the same tag. My current query is <?php $paged = (get_query_var('...
2
votes
2answers
107 views

Query multiple post type and categories

I have a div and inside I wish display by random a post from category-a or a product from category-b. I'm looking for a query to do that. I tried this: <?php $args = array( '...
2
votes
0answers
407 views

Search query - exact post title match

I have a bunch of posts titled something like this... English Language 2015 English Language 2016 English Language 2017 English Language 2018 And on each one of these posts I have a dropdown select ...
2
votes
1answer
2k views

Display related products with custom output

I'm trying to display the related products with my custom html output, unfortunately i'm kind of lost on how to do this. The WP_Query below displays the products that are in stock, what i want is to ...
2
votes
1answer
293 views

Finding all results from database within 500 miles of the given latitude and longitude [closed]

I am stuck into this problem where the main requirement is to find all results from the database which are within 500 miles of the given latitude and longitude. I have stored the lati and longi into ...
2
votes
1answer
102 views

Category archive page - loop through posts of certain tag (with pagination) - pre_get_posts

I have a category archive page (press), which I need to loop through posts of a certain tag (magazines). I tried to modify the query with pre_get_posts, but it is still just showing posts in the '...
2
votes
1answer
24 views

How to prevent Wordpress from retrieving data for the last 10 posts in the database?

According to the Query Monitor plugin, Wordpress is calling four queries for the last 10 posts in the database, starting with this to know the IDs: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM ...
2
votes
1answer
264 views

Calculating Bayesian average for custom post type

I have a custom post type called entries, which holds contestants for a competition. There is a 5 star rating function, the ratings are stored with the entries. So I can get the ratings_average, ...
2
votes
1answer
615 views

Order post by year DESC and month ASC

I have a worpresss 4.0.12 website; i created a custom template category-$id.php in which I have to show post ordering them by Year DESC and by month ASC (or a custom field ASC), the result should be ...
2
votes
0answers
909 views

How to remove duplicate query on page load or make them cacheable

I'm having the same issue as Lletnek where there are the same duplicate queries for get_page_by_path on some of the pages on our website. I have got the queries down to 2/3 on most pages using ...
2
votes
1answer
219 views

How to do a query on custom taxonomies that is uncategorised?

I have a custom taxonomy and I wish to do a query for all custom posts who has no value assigned for that taxonomy (i.e. uncategorised). This is what I have so far: $uncatQuery = new WP_Query( ...
2
votes
0answers
72 views

Sorting posts alphabetical that have single digits

I have post titles that are like this: Episode 1 Episode 2 Episode 6 Episode 10 Episode 14 I try to list posts alphabetically but it ends up showing like this: Episode 1 Episode 10 Episode 14 ...
2
votes
4answers
1k views

Get ID of child from child slug, while knowing parent ID

I have a hierarchy that I need to get data from. It's the child (by slug name) that I need to get while already having knowledge of the parents. Highest Known Parent Page (slug : 'parent') |_ Child 1 ...
2
votes
1answer
2k views

Page navigation doesn't show when query category

Problem: when I do www.example.com?cat=4 or choose category through custom menu or from category widget it shows only first page without navigation at the bottom, where it supposed to be. It's the ...
2
votes
1answer
494 views

Show All Posts Insert Edit Link

When I click to insert/edit link in the tinyMCE rich editor for a post, then click "Or link to existing content", it shows only posts that are live and published. Is there a way to get the list that ...
2
votes
1answer
44 views

How do I query for a post by custom field?

I have a custom field called "song-id" and I'd like to lookup a post by a song-id value. Can someone give me the code snippet for it? (bonus: also looking for a code to use the permalink in the post ...
2
votes
2answers
1k views

Next & Previous (Pagination in this case) Not Appearing

I am using a custom page template for my portfolio. The code is calling the correct number of posts per page but for some reason the pagination links won't show up :-S My query <?php $loop =...
2
votes
2answers
333 views

Conditional to modify query results

I'll admit, I'm not a PHP expert, nor am I familiar with all of the WordPress functions and hooks. I've been stuck on an issue, searching for help without much success, and I was hoping that someone ...
1
vote
2answers
9k views

How do I create a meta box for dates?

I am creating a custom events page and I want to know how to create a custom meta box to save event dates. I don't want it to be a regular meta box because I will be using this to make a custom search ...
1
vote
4answers
8k views

How to tell if $query_var isset?

I tired to use isset($queryvar) but that didnt work, so I implemented my own function qv_isset, but it runs into a problem when $ch is set to 0. $cls = get_query_var('cls'); $ch = get_query_var('ch');...
1
vote
4answers
9k views

Get wp_get_attachment_url outside of loop

I need to get the featured image outside the loop. This is so that I can have a different full-screen background image for each page, set by the featured image. After doing some research I was able ...
1
vote
3answers
1k views

How to show more than 5 posts?

I am running code that shows child categories, and all posts in the child categories. But if there are more than 5 posts in a category, only the 5 newest are shown. How can I show all, or at least ...
1
vote
2answers
6k views

Check if post exists

How can I check if post with name for example Weather exists? If not I want to create it. function such_post_exists($title) { global $wpdb; $p_title = wp_unslash( sanitize_post_field( 'post_title', $...
1
vote
3answers
2k views

How to display all posts with today's same month and day only?

I'm trying to figure out how to do this. I have many posts. I want it so that when someone pulls up the site, the front page shows all the posts that were done on the same month and day -- but ...
1
vote
1answer
19k views

Retrieve and display data from custom db table in admin area?

So, i'm having a bit of an issue with a plugin i'm developing, I wonder if anyone can shed any light on the situation, as many, MANY searches have come back with zero help. :-/ Basically, my plugin ...
1
vote
2answers
4k views

How to modify the query to exclude posts by slug?

How can I modify my query in order to exclude certain posts by slug? Is it possible? query_posts(array('category_name' => 'Mycat', 'posts_per_page' => -1)); Ty
1
vote
1answer
14k views

Looping Through Custom Tax Terms and Displaying All Posts For Each

I'm using the following code to attempt to loop through each of the terms within my custom taxonomy category-film and then output the term name as a heading together with displaying all the custom ...
1
vote
2answers
27k views

How To Get Some Data From WordPress Database Using WordPress $wpdb Query?

I am trying to get some data from WordPress database tables in a plugin. For that, I am using the below code... global $wpdb; $findID = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = '...
1
vote
2answers
5k views

Inserting data into `post meta` table?

How would I be able to insert data into the post meta table? I know how querying and wpdb works but I have no idea how I can just insert it into the table. I have these two fields I want to insert ID ...
1
vote
2answers
111 views

Is there a conditional tag for latest post or do i need a query?

I need to display an avatar in the post info position which i have written the code for but i only want to display it on the most recent post on the home page and not a specific post as this will ...
1
vote
3answers
1k views

Delete post revisions on post publish

Is it possible to delete post/page revisions from the database when a post/page is published? 11/05/12 Answer: See the plugin below by bueltge I want to do this on a site with 5,000 posts and 125,...
1
vote
1answer
23k views

posts_per_page doesnt work

Here is the my custom query ; <?php $Poz = new WP_Query(array( 'posts_per_page' => 3, 'orderby' => 'date', ...
1
vote
2answers
5k views

wp_query orderby title and meta key value (WP3.1)

I have a taxonomy wp_query and i would like to order the list by title and by meta value (numeric value) Have a meta value Interesting = 1 or 0 in the posts Not so interesting posts would be at the ...
1
vote
2answers
10k views

WP_Query for WooCommerce Products

I am trying to display WooCommerce products in custom loop. This is my code: <?php $args = array( 'post_type' => 'product', 'posts_per_page' => 6, 'product_cat' => 'apparel', 'orderby' ...
1
vote
1answer
401 views

wpdb::prepare() isn't working

Here's my code: global $wpdb; $table_name = $wpdb->prefix . 'product_codes'; // Check if codes exist $query = $wpdb->prepare( "SELECT * FROM %s", $table_name ); $existing_data = $wpdb->...
1
vote
2answers
20k views

Deleting data from a custom table in WordPress

I am trying to delete records from my custom table but it does not delete anything. Here is my code: <?php global $wpdb; $retrieve_data = $wpdb->get_results( "SELECT * FROM wp_paypal" ); // ...
1
vote
2answers
712 views

How can I apply a meta query for a single custom post type in the main query?

I have custom post type called event, which has custom fields for start_date and end_date. For the event archive, I'm filtering out "expired" events using the following meta query added to the main ...
1
vote
1answer
4k views

Sorting posts according to view counts not working

I use the code snippet below to get views count of each post on my sidebar.php . everything works but the sorting does not. also it does not get 4 posts, it only shows 1 post although I've written '...
1
vote
1answer
912 views

Undefined WP_Query::has_posts()?

This must be wrong. I was testing something so I did: $queried_post = new WP_Query(array('posts_per_page' => 5, 'offset'=> 1, 'category' => 1)); var_dump($queried_post->has_posts()); ...
1
vote
2answers
3k views

Wordpress Find Duplicate Post By Content

Is there any way to find similar/duplicate wordpress posts by post_content. I have tried "Find Duplicates" plugin but it takes a lot of time to search since I have more than 7000 posts in my ...
1
vote
2answers
6k views

Nginx rewrite rules

I am having some problems with the Nginx rewrite algorithm for WordPress. I am using this for the rewrite and it works good; server_name www.domain.com domain.com; if ($host != 'domain.com'...
1
vote
3answers
4k views

Display page content AFTER a loop of posts

This is probably easy once you know but I'm having trouble getting the static page content to appear AFTER a list of posts. I'm using a named page template which displays posts as a slider and I want ...
1
vote
2answers
4k views

Adding Variables to post query

How do I add custom variables to the wordpress query without having to hit the database twice. In the example below I want to add some meta filters. All this code works fine but I have been running ...