Questions tagged [query]

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

479 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
1answer
211 views

wordpress query - orderby child post date

I have support ticket system which i have built using wordpress. The basic functionality is that when a "ticket" is created, it creates a post. When an admin replies, it then add a child post to the ...
4
votes
1answer
605 views

WP_Site_Query vs. WP_Network_Query in WordPress 4.6

Can someone explain the difference between WP_Site_Query and WP_Network_Query in WordPress 4.6? WP_Network_Query() : Core class used for querying networks. WP_Site_Query() : Core class used for ...
3
votes
1answer
332 views

Custom Queries: Joining On Meta Values From Two Custom Post Types

Hi – I'm hoping this is the right place to be asking this question. I am in the process of moving my full football club website onto Wordpress, therefore using a single database for the information ...
3
votes
0answers
170 views

wp_enqueue_media() slows down my WP site

My website's been incredibly slow and I installed the query monitor plugin to learn more about the issues that caused this. When loading "New post" page, the following query takes 7,3662 (seconds?!) ...
3
votes
0answers
78 views

my function doesn't return my post from today

I'm using gravity form to create some custom post type - as events. Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great. However, I ...
3
votes
1answer
446 views

Query Custom Meta Value with Increment

I have a Query searching for a meta value I have added to my posts (meta-select). I have it feeding out in a loop with 4 results. Let's say I want this loop to start with the meta value "2" and work ...
3
votes
3answers
3k views

Get category slug and display it on a query_post

I just read "How to create option page for wordpress theme" in wp.tutsplus.com - I have a problem with getting categories . there is two parts to my question - Part A - Get category slug and ...
2
votes
2answers
115 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
0answers
410 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
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
620 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
923 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
221 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
1answer
496 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
334 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
0answers
10 views

Conditional query that displays on Woo product attribute pages

I have a custom query set up that currently modifies the product category pages of my website. I would also want this code to affect the product attribute archive pages of my website, but I am having ...
1
vote
0answers
89 views

Category param redirect to post type archive

I'm trying to filter categories by post type. e.g: the following URI will retrieve all post from the category news. https://example.com/category/news/?post_type=post. Here is how I'm updating the ...
1
vote
0answers
40 views

Wordpress default Search function inconsistent in WooCommerce Product Titles

I have a custom query searching by Post title keyword for WooCommerce. But some words return no results and some words do. This simple query doesn't return all words. Words that work: Dressing ...
1
vote
0answers
30 views

WP Query related posts by tags

I want to display related posts ordered by multiple tags. So I need to create a function what will query posts with the most number of tags in common and display them in descending order. But also it ...
1
vote
3answers
49 views

List of the years with posts presented

I need to get a list of the years with posts of given category. Like this: 2008, 2009, 2010, 2012, 2013 (if there were no posts in 2011, it's not included). I try this query, and it works — I get my ...
1
vote
0answers
30 views

get search results from only specific page name in wordpress

I have created a page by using add_submenu_page: add_submenu_page( "pharma-plugin", // parent slug "All Trade Name", // page title "All Trade Name", // menu title "manage_options", // ...
1
vote
1answer
146 views

Get posts by category with pure SQL query

I have a meeting post type, whose titles automatically get set to a date of the form m/d/Y. I have the below query which gets all unique years from the post titles by selecting distinct values after ...
1
vote
0answers
233 views

Filter posts in category archive page by year using a dropdown

I'm trying to filter my posts by year in different categories by changing the query using a dropdown with this code: <form method="post" action=""> <...
1
vote
1answer
211 views

Order by summing multiple values

In a custom post type (products) I want to order products by summing multiple values based on user selection. I use custom taxonomies to filter the products. I could use the orderby meta_value but ...
1
vote
1answer
35 views

How to orderby multiple meta fields with another meta query

I have a custom post type ”events” with meta fields ”startdate” and ”enddate”. Archive query already uses meta query to show only upcoming or ongoing events, but in addition I need to order by both ...
1
vote
0answers
49 views

How do I use AJAX Query in my posts loop?

I have this function in my functions.php. All the AJAX and Query is working but displays the results of the loop right below the AJAX filter. I want the query loop to display in my main theme's ...
1
vote
2answers
25 views

Specific query for custom post type

I am creating a directory and have a custom post type called "listings". I want to display a grid of "Most viewed" listings as well as "Highest rated" listings on my homepage and throughout the ...
1
vote
0answers
85 views

wpdb->term_taxonomy count posts from both published and private posts?

I'm trying to understand why this query won't include both private and published posts when counting and sorting the taxonomy terms. $taxonomyTypes = "AND ( tax.taxonomy = '" . ...
1
vote
0answers
21 views

Query posts intersecting tags and categories

if I have category 'catname' and tag 'tagname' is it possible to visit for example site.ext/catname/tagname and query all posts that are contained in specific category 'catname' and specific tag '...
1
vote
1answer
93 views

Query based on title, with 'compare' => 'IN'

I wanna do a query based on title with a predefiend variable. I cant seem to make it work. What am I missing? Making the query without the 'compare' isnt a problem. $args = array('post_type' =&...
1
vote
1answer
128 views

Order by empty custom field

I order my posts by custom field faq-order. That's work for me: $faqArgs = array( 'post_type' => 'faq', 'meta_key' => 'faq-order', 'order' => 'ASC', 'orderby' => '...
1
vote
1answer
568 views

Search Terms - Querying on either description__like OR name__like in the same Term Query?

In my theme's search.php I have a section set up to show terms that fit the search. I want the term to show up IF the $keyword appears in the term's title or its description. I have it set up to do ...
1
vote
0answers
67 views

Form redirect with query vars to page

EDIT: SOLVED query var and custom post type had the same name story This has been bugging me for few hours so any help is appreciated. I am building a theme, and I have a page named edit-story ...
1
vote
2answers
2k views

WooCommerce: Can't use wc_get_products for custom REST API endpoints

I'm trying to create some custom REST API endpoints which get products with some special conditions, for example one endpoint for featured products. I tried to use the wc_get_products function like ...
1
vote
0answers
193 views

Long running queries

I'm trying to build a PHP script that will pull the 10 most read posts (weekly) and will return me an XML file (so I can link it to Mailchimp). Im also using - Post Views Stats Wordpress plugin by ...
1
vote
0answers
35 views

How to prevent redirect when using the term “page” in query string?

I want to use the query string '?page=1' for pagination of some posts but whenever I do, Wordpress intercepts it and redirects to a post page with that ID. How can I prevent this happening? I am ...
1
vote
0answers
324 views

$wpdb->replace: WHERE?

My plan is to upsert values in a custom meta table with $wpdb->replace. This is what I try: $up_meta = $wpdb->replace( 'spieldaten', array( 'spiel_uid' => $uid, '...
1
vote
0answers
71 views

wpdb php get_var query to get ID for URL image doesn't work for ID over 999

I have been using the following php code in a custom plugin to successfully capture the image ID for a media image URL in Wordpress global $wpdb; $picture_ID = $wpdb->get_var($wpdb->prepare(...
1
vote
1answer
524 views

MySQL variable in query

I've got tenant portal when I need to show running balance for each transaction. Here's query I've written which does what I need it to do. Problem I've got is that it doesn't work in Wordpress. Here'...
1
vote
0answers
520 views

filter RSS feed in URL

I have been busy with RSS feeds lately so I can auto load my content in my email service. I have build a feed (which works) and inside the feed I can toggle preferences by filtering on categories, ...
1
vote
0answers
77 views

Add to query for the_content() on single page

I have a page template that, firstly, has a loop towards the top in order to display a list of links to testimonial custom posts (I'm using a plugin to re-order posts): <?php query_posts('...
1
vote
1answer
250 views

is_search called incorreclty

I just noticed a new error message on one of my websites' pages that lists posts, http://clubcorvettect.com/category/events/ : Notice: is_search was called incorrectly. Conditional query tags do not ...
1
vote
0answers
122 views

Issue with using add_rewrite_rule() for post querying custom fields

Here's what I'm trying to do. I made it so that the posts can store a postmeta value using a meta box textarea field. Here's what I have done so far: I extract the meta value and explode it to an ...
1
vote
0answers
115 views

wp_query get post custom taxonomy in search.php

domain.com/?cat=id custom taxonomy not get post but category get to post How do you write wp_query get post taxonomy? <?php $args_my_query = array( 'post_type' => 'post', '...
1
vote
1answer
65 views

Function to delete a post, it's children and it's grand children (half way there already)

I've got a function working to delete a post and it's children. How can I amend this to delete it's grand children too? <?php function delete_post($sectionid) { global $post; $...
1
vote
1answer
208 views

How to pre populate a form field with a link of a current user's author profile?

I want to include a link to a profile of the current user who's filling out the form on a frontend of my website. That is, to place automatically a current user's author link like this in the "Author ...