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
4answers
3k views

How to order posts by title after they have already been sorted by category

I'm not an expert at much, so please excuse me if this is an easy question... but it's got my head spinning. I have an archive template (adapted from a standard 'enfold' theme template) which I am ...
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. ...
0
votes
0answers
17 views

Boostrap 4 post card seem different on my website

I found a bootstrap 4 card snippet but when I integrate it to my WordPress plugin, it seem different from original form.I want to show posts as 3 column. However some posts hasn't any picture - can ...
0
votes
2answers
859 views

WP Query and date format

I've been using a CPT named "session" that has some date fields. Those date fields are stored via the CMB2 plugin with something like this : $cmb->add_field( array( 'name' => __('Begin :', '...
0
votes
1answer
426 views

Fill the exclude array() in get_posts()

I'm using this code to populate the dropdown menu in a meta box. $parents = get_posts( array( 'post_type' => 'jhk_story', 'orderby' => 'ID', ...
0
votes
1answer
789 views

Database Queries Optimization with new WP_Query

I’m building (mostly with a self-teaching purpose) a simple plugin to query posts from another blog on a MS network via a shortcode (like [network-posts blogs=”8" layout=”grid” columns=”3"]), but I’m ...
5
votes
3answers
5k views

When tax_query used, results disappear (0 =1 produced)

I'm trying to perform a dynamic query that uses a dynamically passed taxonomy and post_type, and displays results accordingly — A user makes a selection from 3 drop-downs on a form, each have a ...
0
votes
1answer
18 views

Trying to get pagination working on WP_Query() post grid

So I've been developing my own theme as a learning experience, and I'm at a loss regarding how to get pagination working. I've tried several things before getting to this point and asking, I just seem ...
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
17 views

Accessing post's meta data based on user's click of a post

I am displaying a gallery of custom post types. When the user clicks a post, instead of redirecting to a single template, I want it to redirect to another page (too easy just change the link since all ...
0
votes
0answers
6 views

Select all sites from WPMU by user, ordered excluting some fields

I want to select all sites from current user in multisite, but ordered DESC, excluding the main site (id = 1) and including these, that are public (with public setting in the result). I know for - ...
1
vote
1answer
21 views

Wordpress Related Post by tags in Single.php

I want to create a related post, but the code I tried shows only related post using only the first tag. I want related post which use all tags. (Because my site is a blog and each post can have up to ...
1
vote
1answer
890 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 ...
2
votes
1answer
625 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 ...
1
vote
1answer
948 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' => '...
0
votes
3answers
762 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', ...
1
vote
3answers
14k 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
23 views

WP_Query of custom post type sorted by meta_key has unexpected results

I do not understand why my code outputs the events in a seemingly random order. It's not sorting by the start_time as I would expect. <?php $args = array( 'post_type' => '...
0
votes
0answers
28 views

My queries intertwine bootstrap 4 post card - dont seem like column

Each one of my post queries (wordpress) interwine to another.Card made by bootstrap 4.How can I fit it? I asked this question on stackoverflow but there's no answer.I think probably it spring from it ...
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 ...
0
votes
1answer
707 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
17 views

Move some posts to end of sort order, even if there is a sort in the wp_Query already

I have a site that lists properties for sale. I have a custom wp_query, with a sort dropdown I created. This dropdown reorders the posts query by date, price (low-high & high-low) and beds (low-...
0
votes
0answers
16 views

How to display custom search results from a selected category of a custom post type?

I have a website that has a blog and a custom post type called proyecto. They are on mywebpage.com/blog and mywebpage.com/portafolio.Each of those pages have a search field and category dropdown ...
0
votes
1answer
891 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
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, [...
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 ...
0
votes
1answer
18 views

Use WP_query to match post types based on custom field values

i'm trying to query posts from the post type Product that match with the current post in the loop from the post type Item, based on the custom fields product-ean and item-ean. For example: i have a ...
0
votes
1answer
764 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
244 views

How do I create an archive page for standard posts?

I've been tasked with creating a portfolio website for a client who also wants a blog. What I've Done Thus Far: I’ve created a custom post type to separate the portfolio work from the blog posts and ...
0
votes
2answers
16 views

How select query is generated in a Custom Post Type?

I have this table that is generated in a Custom Post Type (CPT) Is there an option that I can modify the query? For example, I have this post_type = 'my-type' in wp_posts table. I want to do a JOIN ...
51
votes
3answers
61k views

Query all posts where a meta key does not exist

I am trying to get a query to retrieve all the posts where a specific meta_key does not exist and then create it. I am having problems finding those posts as the query I am testing does not seem to ...
0
votes
2answers
807 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
2answers
886 views

Exclude current post when getting related post on custom post type and taxonomy

The below will return the other post in the same category but it will also return the current post too. Is there a way to exclude the current post from the query? $args = array( 'post_type' =&...
0
votes
2answers
696 views

Comparing timestamps in meta query doesn't work

I want to compare two timestamps in a meta_query instead of comparing two dates in the "Y-m-d" format, each of them stored separately in custom fields, but no success. The first timestamp is an event ...
1
vote
0answers
16 views

Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?

Here's how I'm doing it atm. $query_vars['paged'] = $_GET['page']; $query_vars['posts_per_page'] = $_GET['posts_per_page']; $query_vars['post_status'] = 'publish'; $query = new WP_Query( $query_vars ...
0
votes
0answers
10 views

Filtering get_terms loop by custom fields & custom taxonomy

On specific page I’m displaying posts from my CPT („opencourses”). Posts from this specific CPT are grouped by custom taxonomy („kategoria”) - this piece of code works. At the same page I have four ...
1
vote
2answers
1k 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
1answer
31 views

Custom WordPress post query for displaying time-released content on website

I am trying to implement a "content drip-style/time released content" subscription system using a WordPress query that filters and selects content from a custom post type using set parameters and ...
0
votes
1answer
19 views

Foreach-generated custom tax queries, each with an ajax “Load more” button

I'm looping through custom taxonomy terms to create a WP_Query for each term, then displaying the posts on the front-end. I'm also attempting to adapt this helpful tutorial(and accompanying comments) ...
0
votes
1answer
15 views

1500+ duplicate queries via get_option function (query monitor)

I'm having a huge performance issue once I'm logged into Wordpress. Query Monitor says it's doing over 1500+ duplicated queries with the get_option function executing this query: SELECT option_name, ...
0
votes
1answer
22 views

Custom query for certain post type OR another post type with a certain category

I want to display posts that are either EITHER Post Type A OR Post Type B but ONLY if they are also in CATEGORY 1 Is that at all posible? How do I built my custom query?
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 ...
1
vote
1answer
890 views

Get post ID's from one query and exclude from another

I have 2 instances of the WP_Query class, one showing 4 "Featured" posts and another showing "basic" posts. What I want to do is exclude those 4 latest "Featured" posts from the basic query. I assume ...
0
votes
1answer
12 views

WP Query search for attachments and their exact title

Due to lack of reputation, I must now ask the question. I want to create a search for all images in the media libary. The search result should only appear if you search for the exact title of the ...
0
votes
1answer
15 views

how to handle multiple ajax wordpress queries?

I am having a problem with two ajax action. I have a post grid it has a frontend sorting "ASC" and "DESC". So if I click on "DESC" it changes the WordPress query arg "order by" to "DESC". It works. ...
0
votes
2answers
1k views

Masonry layout within the loop

I have tried to to make a custom query, to some extend. it is working fine. But where i cannot make it work, is it to break after every 3 posts and do same thing (print div.row) and run same loop, For ...
1
vote
1answer
423 views

Why is my category template ignoring post type?

I am currently working on two sites that make extensive use of custom post types. For both we have a defined number of items (cpts) that fall under a particular bucket (categories). One of the sites ...
0
votes
0answers
36 views

Trying to display related custom posts only in same child taxonomy as current custom post

I have some custom post types 'home' and 'provider' that share a custom taxonomy 'states'. The taxonomy is hierarchical so Georgia is a parent of Atlanta etc. In the single template for the post type '...
3
votes
1answer
2k views

paginate_links ignore my format

I need the pagination liks to have the url, like: current_url?p-page=1 current_url?p-page=2 current_url?p-page=3 And so.. The reason I need this is because I have other params in the page. the ...
1
vote
1answer
2k views

How to get list of posts from permalinks?

I am using an API which tracks metrics on parts of my site. The only useful bit it saves though is the URL (permalink). What is the most efficient way to query up all the posts that match those ...