Questions tagged [wp-query]

"wp-query" ambiguously refers to one of two things. 1) WP_Query is a class native to WordPress which allows users to query the posts database using a number of criteria. 2) $wp_query is the global variable that holds the main query object prepared by WordPress based on a given request.

Filter by
Sorted by
Tagged with
1
vote
1answer
881 views

WordPress ignoring LIMIT / posts_per_page despite being in wp_query

Using WP query: $myquery = new WP_Query( array( 'posts_per_page' => $instance['count'], 'meta_key' => 'mywp_post_views_count', 'orderby' => 'meta_value_num', 'order' => '...
1
vote
1answer
795 views

Select only post id and meta value with WP_Query

I'm developing a simple rank plugin, which allows visitors to like the posts and also shows the total like scores for each tag in the plugin's admin page. I need both post IDs (in order to reach the ...
0
votes
1answer
1k views

How to add a custom field and incrementing value for all the published posts

I'm trying to add a custom field value "article" and auto - increment value starting from 1 for all the published and new post starting from the first post. I'm trying with the below code in Mysql. ...
5
votes
1answer
3k views

WP Query where title begins with a specific letter

I want to search for posts with WP_Query() and select only posts that begin with a specific letter. I found a bunch of old posts with filters that were pre-4.4, but since 4.4 there is a title search ...
3
votes
3answers
7k views

How do I get a meta value from WP_Query?

I've got the custom post type foo with meta fields called bar and baz. Now I get the WP_Query object using: $args = array( 'post_type' => 'foo', 'meta_key' => 'bar', ...
0
votes
2answers
720 views

Custom post WP_Query infinite loop error

I am trying to build wp_query loop with custom post type and it seems I get the infinite loop as the result. Here is my code that I am using: $apartargs = array ( 'post_type' => 'apartmani', ...
0
votes
1answer
671 views

Wp redirect to url with ampersand string

i have a url like this: www.url.ui/?keyone=valueone&keytwo=valuetwo&ekythree=valuethree stored in a variable: $url = www.url.ui/?keyone=valueone&keytwo=valuetwo&keythree=valuethree ...
0
votes
1answer
35 views

Display the search results like the original pages

I'm creating my site (locally) and I'm using the starter theme underscores.me I created few pages using bold, italic, and other text styles, but I noticed that in the Search Results page, the content ...
2
votes
1answer
516 views

Working Bootstrap Carousel Conversion to WP - Technical Questions

I have coded a working Bootstrap carousel, it needs to be converted to WP. It's a small chunk of the site, but as a Wordpress newbie, am stuck in understanding the technical issue. So here's what I ...
0
votes
1answer
2k views

how to handle the loop using filling bootstrap grid structure?

i make a code that can fill bootstrap grid structure i used while and for loop in my code but the issue is for loop repeat its value in 2nd row the above picture tells you column 2 and 3 of first ...
0
votes
1answer
814 views

Get post from Category by Priority

I want get 3 posts from event custom post type. But i want to do that by category priority. If "featured" category has 3 upcoming event then i want to show 3 posts from it, if "featured" category ...
0
votes
0answers
21 views

Sort posts numerically by converted date format

Updated for clarity: I need to convert the post date format from Y-m-d to mdY and sort by mdY numerically, not by the actual timestamp. My goal is to order the posts by month first, then day, then ...
0
votes
0answers
9 views

Where my home page and font options has gone?

I accidentally deleted my home page. I have a customed theme. I hit restore page from trash yet still a different new page exists as my home page. I searched my pages and I see a different page ...
0
votes
1answer
1k views

How to pass taxonomy terms to WP_Query along with $args?

I created a cpt and custom taxonomy associated with it. Lets say custom taxonomy name is Sports. I added terms to it - football, basketball. Now, i want to fetch post titles tagged under football ...
0
votes
0answers
9 views

Sorting posts By Taxonomy using 'post_clause' filter

I have a table list in my plugin's admin panel that has taxonomy columns. I'm trying to add some sorting functionality for those columns and I'm using the post_clause filter to alter the query to ...
5
votes
5answers
15k views

Get post with multiple meta keys and value

I am trying to fetch a post based on the following meta keys. post_code with 432C location with XYZ Both belong to a CPT. I'm trying to fetch the Post with both these meta_values. I Don't Want an ...
0
votes
1answer
24 views

How to get meta key list efficiently?

I have this function to get the meta keys for all the post types. public function pgggo_custom_post_type_keylist() { //gets the list of post types $...
1
vote
1answer
1k views

Slow queries on a huge database

I have a huge database with over 250,000 posts. I have ran every optimisation i could have and searched every possible solution on the internet. Lets say i have this query where i want to get the ...
0
votes
2answers
772 views

How to query images from a post to use in a slider

I am trying to pull images as attachments from a particular post (custom post), ...and I'm using the example within WordPress codex codex example to display all images as a list ...except the images ...
1
vote
3answers
13k views

How to query posts from specific authors and categories using WP_query?

I currently have a WP_query where I am getting posts from a specific set of authors. To this, I want to add specific categories as well. $args = array( 'author__in' => $authors, 'posts_per_page' =...
0
votes
1answer
3k views

forming WP_Query for posts of all post types but from specific categories

I need to get post from blog, custom post type 1, custom post type 2. custom post type 3 and either from category 1 or category 2 or category 3 or category 4 or category 5 or category 6 or category 7 ...
9
votes
5answers
28k views

Page template query with WP_Query

I would like to query only pages with a certain page template with WP_Query or a function that would return the post object, but I can't find any information about that on the official codex.
0
votes
2answers
1k views

Custom search: Search posts but display parent page in results

I'm using Wordpress 3.5.1 with a modified twentytwelve theme. My main site structure is based on the Smooth Slider plugin (jQuery Cycle). I have Pages that contain only a shortcode (for example, [...
0
votes
1answer
13 views

How to show specify category template for both parent and child category

I tried to create a category template apply for parent and child specify category. I has create a file name 'category-1.php , in this file I used the loop for get the list of post: <?php if (...
0
votes
1answer
750 views

How to get post meta for custom post type and taxonomy

I am trying to access post meta for custom post type and taxonomy using WP_Query and then query the posts with that specific post meta. So far I have tied the following code: $hot_args = array( ...
2
votes
2answers
1k views

How to display custom field on homepage

I am new to custom fields thing. I am working on a movie review site. And wants to add movie story or plot field, I have successfully added the custom field named Story and its content is displaying ...
1
vote
2answers
906 views

The pagination on index.php doesn't work on a first page

I have index.php with a pagination. The permalink settings is plain permalinks. I have a correct pagination view when I open a page /?paged=2 but if I open just index.php I have all posts without ...
0
votes
2answers
14 views

how to pass args for archive.php query?

I am trying to pass args to archive.php so that I can order the posts, set the number of posts, etc.. but the query is done like this <?php if (have_posts()): ?> <?php while (have_posts())...
0
votes
1answer
982 views

How can I update post meta inside a WP_Query loop or the WordPress loop?

How can I update post meta inside the WP_Query? Does this mean inside the loop? Sorry, I'm not too technical about this. This is the code I'm using: <?php if(isset($_POST['jolly'])){ ...
0
votes
1answer
19 views

How to get the latest post list (of the parent custom custom type)

I am looking for a solution to get the latest list of custom parent posts. example: Post A Child Post A Child Post B Child Post C The bold list items are the posts/pages I want to retrieve. I ...
0
votes
1answer
2k views

Custom post archive with search, is_search() is false?

I have a custom post type, and have created an archive template, archive-custom_post_type.php, which includes a search form. I am then using pre_get_posts to add parameters to the query to filter my ...
0
votes
1answer
36 views

Select multiple categories with is_tax

i have a good function for exclude out of stock products from category. The problem is i want exclude for more than one category (really i want show only in one category, but i think this is the way. ...
1
vote
2answers
8k 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' ...
0
votes
0answers
21 views

how to retrieve specific product attribute value in an sql query?

I am looking for some suggestion on how to run a query on wp-term with multiple "same column name as different attribute name" bottom line I am trying to query woocommerce products + all their ...
4
votes
5answers
2k views

Show related posts by category but ignore one category

I'd like to show 4 related posts (without a plugin) at the bottom of my blog. However, I want to exclude a certain category. For example, if my blog post is in category 2 and 3, I want to ignore ...
0
votes
1answer
28 views

Query custom post type and custom field by URL parameters

I have a custom post type staff. and a custom field alphabet for posts in that post type. Each staff will be assigned to a letter either A or B ... Z based on the first letter of the staff's name. On ...
0
votes
2answers
97 views

find posts that don't have a custom taxonomy

I am using a custom taxonomy series to keep track of posts that are in a series. I would like to find the posts that do not have a series. I have the following query: global $wpdb; $pr = $wpdb->...
0
votes
2answers
17 views

How to get only present and past posts with post_date

An administrator wants to make posts for a future date but not visible for visitors. The posts come from a custom WP_Query inside my plugin so the basical WP behaviour does not work in this case. I ...
0
votes
0answers
47 views

Post Type Search Gives Unexpected Results

I am working on a WordPress site that has several custom post types. Of course this lends itself to writing a custom search form. However, the results from test searches have been less than ...
0
votes
0answers
14 views

How to get user avatar via WPDB

For my REST-API i need to get for every post the username, date ... and Avatar ! $query ="SELECT POST.ID, POST.post_title, POST.post_date, USER.user_nicename FROM wp0x_posts POST INNER JOIN ...
1
vote
1answer
20 views

WP_Query To call data from diffrent tables

I need to retrieve data from multiple tables , wp_postmeta to get posts with a specific type ( question ) , wp_user for author informations and also wp_comments . I need those information to use them ...
0
votes
0answers
12 views

match and update acf fields with array values

i created array from gravity forms entries that has information about students payment. this array contains only the values i need about payments. $arr: [6047] => Array ( [0] ...
0
votes
0answers
14 views

WP query custom search by meta query nested ACF repetear field Group > Repeater

So I have searched the web but didn't found quite an good solution to this problem. I am having nested ACF field with a repeater inside a group and I want to display and order wp query by that item ...
1
vote
0answers
12 views

Wordpress custom post type with meta - how to retrieve with wp_query

I developed simple plugin and now would like to get only posts where start_date < $now & end_date > $now so I have to add meta_query to the args but how should it look like? $args = ...
1
vote
1answer
13 views

Get a list of posts with associated meta_value

Recently I began to use the Custom Fields. I would like to display a listing of posts which contains the meta_key "oldtimer" and also get the corresponding meta_value. Here is the expected result: &...
0
votes
0answers
11 views

One of two similar WP Query is very slow

I have two WP Query are very similar. one is fast and another is very very slow. I have already test two query via mysql directly. the fast one: SELECT wp_posts.* FROM wp_posts INNER JOIN ...
0
votes
0answers
7 views

in WordPress Loop update_user_ meta with Current Month and Year as Meta_Ley

I am making a page for my wordpress authors to see there stats. For the same, i first loop through all author ids, then i loop through all of there posts, and sum the post views meta key for all. I ...
0
votes
1answer
38 views

unique post in “$args” of wp_query display more than one post

I can't find the rights arguments to display only one post of a category when I click on a div. I call the post with Ajax and I display it in a div popup.Perhaps these arguments are not sufficient, or ...
6
votes
2answers
30k views

Loop within a loop?

I'm using a couple of custom wp_query loops on my page, the first one retrieves news from a certain category then displays a small excerpt from it with the permalink. The second one is another ...
0
votes
1answer
24 views

Display current post position in Elementor Posts widget

I'm using Elementor 2.6.8 + Elementor Pro 2.6.2 I'm designing an Archive template to display a list of Custom Post Types filtered by custom taxonomy terms. I'm using Posts Widget from Elementor Pro ...