We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [query]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
8 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 ...
3
votes
1answer
445 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 ...
0
votes
0answers
18 views

Custom Query with Sticky Posts

I’m trying to write a custom query which filters by category and shows only a certain number of posts. So far that’s a simple thing along these lines: $args = array( 'showposts' => 1, 'cat' =>...
0
votes
1answer
21 views

How to search through “post title” and “tags” using WP_Query?

In my custom search form, i'm currently using these kind of $args with my WP Query: $args = array( 'post_type' => 'post', 'posts_per_page' => $postsPerPage, 'offset' =&...
-1
votes
1answer
24 views

how to use transient method?

It was suggested to use a transient method to remove the duplicate queries Duplicate Queries Why does this don't work? Is it the wrong way to use it private function get_acf_list() { if(!...
0
votes
0answers
28 views

Get list of all existing meta keys [duplicate]

I'm using Custom Fields in my post type and I'm looking for a way to get a list of all existing meta keys. I know I can get all meta keys for a specific post with get_post_meta() but I need all ...
0
votes
0answers
20 views

Custom Query - exclude child category post from parent category post loop

I'm trying to change the way wordpress displays posts under category pages. Ex: Cat1 (contain 1 post) Cat2 (contain 1 post) Subcat2 (child of cat2 contain 1 post) Cat3 (contain 1 post) In the ...
1
vote
1answer
505 views

MySql Query very slow

I have a problem with a query on my website. When I load the page it is incredibly slow and only after over 12 seconds the content starts showing. I have installed a debug plugin and found the query ...
0
votes
1answer
776 views

Run an update query in a function

I need to run the below in a function, it updates my database if certain conditions are met. I can't get it to work and I can only assume its because of the "SET @newnum" at the beginning. I've echo'...
0
votes
0answers
17 views

PHP Warning: mysqli_error(): Couldn't fetch mysqli in

I am new at this, so this is my case. I am getting this error on my Wordpress site and I need someone to point me out where to search the problem. I know that is written in a log file and here it is, ...
0
votes
0answers
30 views

Meta query orderby meta_value_num sorting by role first

I want all of the results to order by meta_value_num, but it's ordering by role first. How do I get them to ignore the role order? Here's my code: $user_query = new WP_User_Query( array( '...
0
votes
1answer
17 views

Custom Query returns array, but I can't see it's elements

guys! I have the following problem to solve - I am using Private Content plugin which divides users into categories. I need to show all posts from the category that the author is part of. I tried ...
1
vote
2answers
797 views

How to create a WP_Query to search the Title or Tag?

I have created a search using WP_Query, it seems like this query is looking for the queried term in title AND tags. Is there a way to have this search the title OR tags? $s = $request['s']; $tags = ...
0
votes
0answers
8 views

Creating a table from another's results using WP $wpdb functions

Below is the query and function I use to create a table from another table's results: $mytable = "myCustomTable"; $thisSQL = "SELECT p.ID, p.post_title, p.post_author, p.post_status, COALESCE( ( ...
1
vote
1answer
33 views

Duplicate Queries

While using the query monitor plugin I could notice I am making a database query 4 times. I am using OPP. So I have a method that gets me a list of posts by querying the database. I have to do this 4 ...
0
votes
1answer
41 views

Should I reset $wp_query?

I am not totally new on WordPress but the query thing is a bit confusing to me. I searched the web and read a lot of articles, but I couldn't find what I needed. Maybe it could help a lot of people ...
-1
votes
0answers
11 views

How do you query custom post types with the same category name as the post title?

How do you query custom post types belonging to a category with the same name as the default post title of the post where the post types are displayed?
0
votes
0answers
21 views

Is it possible to have 2 Args with pre_get_posts?

Is it possible to use the pre_get_posts hook using two sets of args? For example, if I want to modify my main loop to first display all products that have a tag sponsored and then display all the ...
0
votes
1answer
502 views

how to insert missing tags into the posts through mySQL?

I am looking for a SQL query to insert a tag to multiple posts from a specific category. A pseudo query looks something like this: INSERT INTO POSTS VALUES TAG = "tagName" where Posts in_category("...
0
votes
1answer
48 views

Custom post type order by post_title

I got a custom post type called "employees" and this is the query I use with FacetWP (plugin we are using). We want to sort the employees by post_title. <?php return [ "post_type" => [ "...
0
votes
0answers
17 views

Static position inside an ajax-called loop

0 I am serving an output of five posts in my homepage and upon scroll down, I use an Ajax call to implement a load-more functionality, which loads a next series of 5 posts. So, upon scroll down, $...
0
votes
1answer
602 views

Divide WP_Query posts by date & post type

I have a WP_Query that divides 2 Posts types by date but the functionality is not there. Currently it outputs the dates and posts on the same level like.. -Date -Post -Post -Date -Post -Post What I ...
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 ...
1
vote
2answers
530 views

How to List Parent Term Links for Custom Taxonomy With & Without Children?

I have a Custom Post Type of "projects", that is categorized by a Custom Taxonomy of "industry", which is heirarchical. Projects & sub-projects are assigned to the industries. For Example, the "...
0
votes
1answer
772 views

How to add parameters for custom post type

I need to add a parameter to this custom query below. post_type=customer-stories&tag=microsoft,google I now need to add a parameter that will allow me to customize how many of each type of ...
0
votes
0answers
26 views

Tags do not work

I can’t figure out how to add tag support to this code. Absolutely all posts are displayed on the tag page <?php $args = array(); $cat_id = ""; $queried = ...
0
votes
2answers
588 views

Get first comment link on the post itself

I have this function and a link to a post: <?php foreach ($results as $id) { $post = &get_post( $id->ID ); setup_postdata($post); <li><a <?php href="<?php ...
0
votes
1answer
491 views

How to do a MySql query in WordPress?

I want to get the last auto-incremented ID's value of a particular table. I found a MySql function on the internet to do that. But I'm not sure how can I use this function in WordPress to get the ...
0
votes
1answer
633 views

How to get all images in Media Gallery with pagination?

I want to get all images in the image gallery with pagination so that I can use infinite-scroll with it. The infinite scroll works but it's taking the posts' number of post, not the images. That ...
0
votes
2answers
613 views

merge two query arguments into one WP_Query call

I'm overriding WooCommerce's default search query to include searching by SKU as well. // default search query $query_default_search = new WP_Query( array( "post_type" => "product", ...
0
votes
1answer
1k views

Count posts for pagination

I'm doing the pagination for a web. < Previous (pagenumber) Next > is easy, already done. But now I need to add a selector to go to a page directly (ex: to page 7), to do so, I need to know how ...
0
votes
2answers
685 views

Conditional posts in WP_query for search

I have a custom post type that im trying to limit results in search. The CPT is a deal/coupon, with a start and end date for each of the deals. What I'm trying to do is only show these posts in ...
0
votes
0answers
23 views

Display the terms from multiple taxonomies in a Custom Post Type

I have a Custom Post Type and I have different custom taxonomies. Every taxonomy has one or more terms. For example: Custom Post Type: Activities | Taxonomy 1 | | Taxonomy 2 | | ...
1
vote
1answer
17 views

difference between like '%%%var%%' and '%var%'

What is the difference (if any) between: $ids = $wpdb->get_col($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_product_attributes' AND meta_value LIKE '%%%s%%';", $code))...
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 ...
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 ...
0
votes
1answer
12 views

Including taxonomy in searches

(Fairly new to WordPress, but I'm a React / NodeJS developer) I have a basic search function that search a custom post_type (listings). It makes use of the standard built in get_search_query and ...
0
votes
1answer
586 views

Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice

Anyone encountered this issue? I have created a custom php script which adds a new post by using wp_insert_post() but everytime I run the code it creates a 2 new post where in it should be only be ...
0
votes
2answers
32 views

SQL query to list all posts of specific post type with a specific set of associated postmeta values as a column

I want all posts of type 'ajde_events' as a row each with a column for some basics from the post table and some ( not all ) associated postmeta values. I have cribbed the following from this post How ...
1
vote
1answer
595 views

I am trying to hide a custom post type category to logged in users with Pre_Get_Posts

I have a custom post type in my theme called portfolio. It's categories are called project-categories. I am trying to exclude a project category for logged in users. I cannot get this to work at all. ...
0
votes
1answer
35 views

How to avoid a duplicate query from using wp_nav_menu?

My theme need to render 2 menus in homepage. The rest pages only need one. As result is only homepage got duplicate query warning. After tracking down, I found out this was cause by wp_nav_menu. How ...
0
votes
1answer
753 views

Query Pulling the same post twice

After seeking help and failing, I managed to write a query for Wordpress that does exactly what it's suppose to do, however it pulls the post that it's suppose to in twice. I've stared and stared at ...
0
votes
1answer
593 views

Creating a custom search for a specific post type

Ok, so we know Wordpress comes with a built in search form. However, I've created a custom archive page that lists posts from a specific post type. I would like to integrate a search box that only ...
0
votes
2answers
800 views

wordpress udpate query not equal to

I am trying to write update query where id is not equal to 5 i want output like this but not working. UPDATE `wp_messg` SET `is_read` = 1 WHERE `job_id` = 1 AND `biv_id`!=5 $id=5; $wpdb-&...
0
votes
1answer
48 views

Custom Post type slider with thumbnail navigation

I am trying to make a slider for a custom post type with quite a few custom fields. Ive got the query and fields displaying fine. But now to get it into a slider Getting each post in the loop ...
0
votes
1answer
1k views

WP Query - Search in title or author_name

My need is to have a WPQuery that searches for posts which title is 'test' OR author_name is 'test'. Here is the code I tried: $search_query = get_search_query(); $args = array( 'relation' =>...
0
votes
0answers
14 views

Display posts from today and future in Elementor 'posts widget'

According to Elementor documentation https://developers.elementor.com/custom-query-filter/#Multiple_Post_Types_in_Posts_Widget I need to display future posts including the post from today. We want to ...
0
votes
1answer
708 views

Pagination is not working on custom query inside a custom home page template

I know this is a duplicate question. But to comment on existing question, I dont have enough points. So here we go.... Pagination is not working on custom query inside a custom home page template. ...
0
votes
1answer
24 views

The search engine of my website finds only posts and not pages, how can I solve this problem?

I have a curious problem with the Wordpress search engine of my website (the one that makes URLs as http://sitename.com?s=searched+word). When I installed Wordpress I noticed that when I used the ...
0
votes
1answer
719 views

Merge two queries and remove duplicate

I want to merge two queries together and remove duplicate. I got it working individually. Now I got it working together but the results are not mixed and the duplicates are not removed. So I got the ...