Questions tagged [query-posts]
Set up The Loop with query parameters. This will override the current WordPress Loop and shouldn’t be used more than once. This must not be used within the WordPress Loop.
1,242
questions
1
vote
1
answer
655
views
Filtering out child category posts from parent category archive not working
In this example cat 5 is the parent category, and 42 is a sub-category. I the main category 5 archive I don't want any posts from sub-category 42 displaying.
Why isn't this working?
function ...
0
votes
1
answer
34
views
Main site single-property.php design, as homepage of a multisite
I've been researching how to do this for some time now, and I'm coming up short.
I have my main blog, example.com, which we've created a custom post type of Property. I'm needing the exact layout and ...
0
votes
1
answer
11k
views
How to get posts from a current post's month?
I want to display the titles of the post of the same month as the blog post.
I tried this ..
<?php $year = the_date('Y')?>
<?php $month = the_date('M')?>
<?php $theids = $wpdb-...
2
votes
1
answer
74
views
Taxonomy.php issue with search and filters
I'm trying to create a custom taxonomy.php page where my users can refine search into that context. I've tried to create a kind of loop like:
<?php
if(!empty($_GET['ending']))
...
1
vote
1
answer
3k
views
How to build a WP_Query using mulitple tags and using AND or OR operator between them
I'd like to craft a query to return posts based on the conditional presence of certain tags. The pseudo query is: return posts with "((tagA OR tagB) AND (tagX OR tagY))". But I'm having issues ...
0
votes
1
answer
27
views
How to sort posts according to meta value?
How can I sort all the posts according to their meta value? I am using the below code:
$args = array(
'meta_query' => array(
array(
'key' => 'wpcf-stream',
'...
0
votes
1
answer
214
views
Sort Events by Venue Title - Sort Post set by related post ids
In wordpress, I am using The Events Calendar Plugin to host events. This includes two post types: events and venues.
On an index page, I would like to list ALL events, but ordered by their ...
0
votes
1
answer
5k
views
How to provide meta_key array to wp_query?
I'm trying to build a wp_query, so far I've managed to get desired result using following query.
$args = array(
'meta_query' => array(
'relation' => 'OR',
array( //check if ...
2
votes
2
answers
3k
views
_wp_page_template to dynamically use template
I'm wondering if it is at all possible to set display a page template chosen by the user within the context of a query_posts using get_template_part. In other words, I have set up a page template to ...
3
votes
3
answers
153
views
Are there any scenarios where the query_posts may be used?
I feel there is a red button saying "Do not press" below query_posts(). For some time I am trying to demystify this phenomena with very low success to be honest.
For example, probable the main ...
3
votes
2
answers
620
views
Is `query_posts` really slower than secondary query?
I know the main query is fast, since it gets data after parsing the URL and after WP_Query has been instantiated. We are in OO PHP.
But is query_posts really slower than some secondary query that ...
16
votes
3
answers
3k
views
Why query_posts() isn't marked as deprecated?
There are two query_posts() functions technically speaking. One query_posts() is actually WP_Query::query_posts() and the other is in global space.
Asking from sanity:
If global query_posts() is ...
-1
votes
1
answer
513
views
Filter Query Post by Custom Fields(by date)
I want to filter query_post using the 2 meta keys start_date and end_date, i want to get my posts to divide it by upcoming events and past events.
start_date and end_date is stored in the timestamp ...
1
vote
1
answer
951
views
pass query string on url to filter media
I have an author page which shows all uploaded media by that author. Each media can have tag1, tag2 or tag3. I would like to add an option where I can show on that same page only tag1 media without ...
2
votes
1
answer
2k
views
Query with custom taxonomy not working
I have custom post type 'mix'. And custom taxonomy 'meal'. And categories in custom taxonomy (one of that is with slug: breakfast)
I have problems with making query. My code is :
$args ...
1
vote
2
answers
7k
views
posts_per_page override by default settings
I'm running some template files outside of the actual theme and I am displaying some posts on this templates. Everything worked absolutely fine but some days ago (maybe the update to 4.5) the default ...
1
vote
0
answers
671
views
Frontend Post with JQuery AJAX to Php Issue
My problem is the following. I'm trying to make users publish custom post_type by frontend through a form like this:
<form id="msform" enctype="multipart/form-data">
<fieldset id="...
0
votes
1
answer
66
views
Trying to show Wordpress category query result as background image
The code is working fine so far, but I want to show the post thumbnail as a background image inside the li tag. Been trying many variations, but can't work it out? Here's the code:
<div class="...
-2
votes
1
answer
907
views
How to remove post duplicate when using query_posts('offset=1')
I used query_posts('offset=3') in index.php, while there exist a problem in pagination. In all page it show the same content of first page.
How to solve this problem?
1
vote
1
answer
468
views
Query all posts if multiple meta key don't exist
I'm trying to get all posts that don't have a meta ket that starts with aa_. I can do it this way
$args = array(
'posts_per_page' => -1,
'category__in' => 23,
'meta_query' => array(
'...
0
votes
2
answers
2k
views
Fetching $_POST from Page Template into functions.php
I'm having an issue with the order WordPress is loading page templates and functions.php.
I have front-page.php which has $_POST['sort-by'] allowing users to sort posts using a drop-down menu.
It's ...
0
votes
1
answer
71
views
order posts by `meta_key`, Does not display posts that does not have `meta_key`
I'm using this query orderby meta_key for show posts.
if one of the posts does not have vip_row meta, So not shown;
Is it possible that if one of the posts does not have vip_row meta to be displayed,...
1
vote
3
answers
2k
views
Unable To Get Published posts using query_posts
I'm not sure why this is not working as its a very simple query. It works when i pull all posts including pending, but not when i want to get posts that are only published.
I have a function to get ...
-1
votes
1
answer
2k
views
Modify Blog Module layout in Child theme
I need to adjust how the featured image is displayed in their blog module.
I need to change the display of the Featured Image from an IMG tag to a Background Image. So I can modify the frame (DIV) of ...
0
votes
1
answer
39
views
How to set class to "current-page" on the currently viewed single post within a CPT
I have a custom post type, "case". I'm currently editing the single-case.php file and in my sidebar I have the following piece of code:
<?php
$case_query = array (
'post_type' => 'case',
...
0
votes
1
answer
183
views
Create a hierarchical loop at predefined markup requirements
I try to achive this in wordpress based on my theme:
fullpage.js demo
So I have a predefined markup for vertical sections (parents) and one for horizontal slides (children). Parents only contain ...
1
vote
4
answers
695
views
2 loops on page - one with orderby rand second orderby date
What I'm trying to achive, is to set 2 loops on one page. First one takes 11 latest posts and sort them in rand order. Second show the rest of posts ordered by date.
FIRST LOOP
$args = array('...
1
vote
1
answer
1k
views
Improving WP_Query for performance when random posts are ordered
I have made a new query after I've asked a question about my query_posts code... you guys didn't find that great, so I decided to change that.
I made this:
$page = (get_query_var('paged')) ? ...
3
votes
1
answer
7k
views
How to make draft posts or posts in review accessible via full url / slug?
I am running a website with WordPress 4.2 and have changed the way draft posts or posts in review status are displayed to non logged in users (these posts are, too, visible to anyone who visits the ...
0
votes
1
answer
554
views
Does wp_query and query_posts affect website performance? [duplicate]
I've been aware about the difference of wp_query and query_posts. I just want to know what impact does both query methods to the performance of the page? Which query method makes the page load quicker ...
1
vote
1
answer
3k
views
Change query_posts to WP_Query in page but does not work
I have this code in page.php and it calls the template part for my home. Inside the home.php i used query_posts instead of WP_Query and i wanted to change it into WP_Query.
I tried changing it but ...
1
vote
1
answer
1k
views
Show all taxonomy's terms' posts having another taxonomy's term in common
I am building a website which displays web radio stations. I have created a custom post type called "stations" and 2 taxonomies called "genres" and "locations". In my page I display all genres grouped ...
1
vote
0
answers
163
views
How to display an other custom post type in a different custom post type's archive?
Background:
I need to display all posts of a custom post type called "recipes", that have a specific taxonomy "fish", right under the permalink "www.mysite.com/recipes/fish".
What I have done:
I ...
1
vote
0
answers
49
views
How to retrieve an array of post IDs by a particular value stored in a custom meta's array
I have a custom post type 'projects' that has custom post meta 'members'. 'members' stores an array of another custom post type's IDs.
I'd like to do loop through the 'projects' posts that have a ...
1
vote
1
answer
2k
views
Call to a member function have_posts() on a non-object on normal loop
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'MY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
...
3
votes
1
answer
7k
views
Meta Query with date and time on the same Day before given time
I have a metaquery for a custom post type "events".
Their start date is stored as a meta field in this format:
2016-02-05 19:00:00
These are my query args:
$args = array(
"posts_per_page" => ...
1
vote
2
answers
5k
views
ACF Custom Field WP_Query, but need to get all posts, if field doesn't exist
I have a custom ACF field set on all posts, called event_date, I would like to grab all posts within a given category, but have posts that have event_date defined put first in DESC order of event_date....
12
votes
1
answer
43k
views
How to get post content by calling ajax?
I am working on a plugin .I have a custom post type team.Custom post has four posts of different categories.I used this code to send post id of each using ajax.
$(document).ready(function () {
...
1
vote
0
answers
877
views
Random ajax load only works with posts_per_page set to -1
I created a post loader shortcode, that uses AJAX to load posts. Even though I can set the order and order_by query parameters, the order_by should be random. From what I've seen on the web, ajax load ...
0
votes
1
answer
353
views
How to order by datediff in WP loop?
I have a custom post type for events with a custom field named event_start_date, and I want to sort the archive loop according to the nearest event_start_date.
In other words, the event with the ...
1
vote
0
answers
36
views
Homepage's content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
I have a custom field in my home page called "Featured posts". There are two fields: title and post. The post field returns post_object with post_type as posts. In my functions.php I have added the ...
1
vote
1
answer
178
views
Query posts based on the meta key values of logged-in users?
I searched in WordPress Codes, and all of the online forums and tutorials about this but could not find any relevant solution. What I am trying to achieve is to create a query that lists posts for a ...
0
votes
1
answer
111
views
Dynamic archive of posts by date
I'm currently working on an intranet site for a big company and based on the project description, there will be a lot of articles posted everyday so this website will need various archive pages with ...
0
votes
4
answers
1k
views
wp_posts table: safely remove unused columns to save database storage
i search about it on google but didn't find any thing. I want to remove my wordpress wp_posts table's unused columns, to save my database storage...
I know if table column is empty it will not ...
0
votes
1
answer
48
views
All categories displays the same posts
Googled for hours and couldn't find solution anywhere. =)
This solution doesn't work as well:
Display all posts in current category
Regardless of how I alter my query_posts - it always displays all ...
0
votes
1
answer
9k
views
query_posts by category_name and custom taxonomy
I want to display posts filtered by category_name and custom taxonomy-term:
I have
function channel_init() {
// create a new taxonomy
register_taxonomy(
'channel',
'post',
array(
...
0
votes
1
answer
44
views
Pagination, query more pages at once
I'm wondering if it is possible to do such thing on Wordpress, I have an infinite scroll to display my posts, I'm keeping track the pages updating the url:
mypage.com/news/?pag=3
and I have a code ...
0
votes
0
answers
2k
views
Imported Content Doesnt Show Up On Frontend
I found similar problems posted couple times, for different custom post types, but none of the solutions worked for me and these, other questions, didnt have much info provided, I'll try to give as ...
0
votes
2
answers
100
views
how to repeat taxonomy in different places on wordpress
I need help with this.
I need repeat taxonomy in two places, are post, and coupones post, this code is in clipper theme.
this code put taxonomy stores in coupon.
add_action('init', 'clpr_post_type', ...
1
vote
1
answer
3k
views
Archive for custom taxonomy lists all posts instead of current taxonomy
I'm using the Types plugin for a custom post type "Session", which has the custom taxonomy "Semester". I would now like to create an archive page for each semester which is automatically generated. ...