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.

Filter by
Sorted by
Tagged with
0
votes
1answer
277 views

Pagination does not work with query_posts()

I trying to add pagination to my WordPress website, it's working fine in main index page, I am trying to create different main pages for category issue with category pages, when click any link of ...
1
vote
1answer
23 views

How to edit this code to get the categories in achieve page?

I was building part of my category.php which will get posts from custom post type "product" and sure which will be included in the category what happen was it get ALL the posts from the custom post ...
1
vote
1answer
786 views

Category with post type pagination returns 404

I have a category template with a custom post type that looks like: <?php $category = get_query_var('cat'); $paged = (get_query_var("page")) ? get_query_var("paged") : 1; $args = array(...
1
vote
1answer
3k views

Query_posts $query_string

I have a query that looks like: query_posts($query_string."&post_type=attachment&posts_per_page=9&paged=".$paged); I'd like it to looks something like: $args = array( 'paged' => $...
0
votes
1answer
569 views

How do I display posts of a specific day?

<?php /* AJAX.php */ //ajax call with no privalidges, a user that is not logged can access load-more add_action('wp_ajax_nopriv_japi_load_more','japi_load_more'); add_action('...
0
votes
0answers
47 views

My entry results are not consistently alphabetized

I have a specific query that shows all results. Those results are ALMOST alphabetized except for one entry. I also have a menu that allows you to see those entries based on tax term. When you do this ...
0
votes
0answers
17 views

Make recent post display recent updated, instead of recent published

Is there a way to show posts in the order of recent updated, instead of recent published? Is there a plugin to hook the internal query function, so that I don't need to make changes in template file?
0
votes
1answer
394 views

How can I comment comma-separated array values?

I realise this is perhaps more of a php question rather than WP-specific, but figure/hope it's relevant. I annotate my code probably more than is needed (because I know relatively little about this, ...
0
votes
0answers
92 views

admin-ajax.php returns “No Script Kiddies!” sometimes

I have a custom plugin which requests for next set of posts in the given category and displays them in a specific way. The ajax call to admin-ajax.php is returning "No Script Kiddies!" thought many ...
0
votes
1answer
122 views

Assign a class to first element in category in loop

I am trying to do the following: 1) assign col-lg-4 class to the first element in the loop, when there are 3 or more posts within the given category. 2) assign col-lg-8 class to the first element in ...
0
votes
1answer
194 views

query_posts -> get page_id from custom field

I'm customizing a page template and having an issue with getting a page id from a custom field. The value of the custom field contains the page ID whose contents are to be called. For a normal page ...
0
votes
1answer
208 views

Orderby query does not work for custom fields even with meta query

I have written the following query to fetch a list and want to show the list of names in ascending order. I was earlier trying to pass meta_key and meta_value as arguments but it would not give the ...
2
votes
1answer
47 views

Hiding posts in a list from specified categories

Question How can I modify this code to not show posts from new categories that we just added. I searched other similar answers on this site [such as: Exclude category on blog list page ] but not ...
1
vote
0answers
78 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('...
0
votes
2answers
2k views

Get post by tag

I want to get several post by tag. So I try to use get_posts() function: <?php $args = array( 'numberposts' => '3', 'post_status' => 'publish', 'tag' => 'travel' ); $...
0
votes
1answer
825 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 ...
0
votes
1answer
49 views

How do I add a relation parameter to my filter query?

I am building an AJAX post filter using a single form with three select fields that allow the user to sort by three separate taxonomies (category, region, and country). Everything is working well for ...
0
votes
0answers
65 views

How to order posts, that have already been filtered by custom taxonomy, by their category names?

My question is not a duplicate, because in my case posts have already been sorted by custom taxonomy term. The question is how to order posts by their category name AFTER they have been sorted by ...
1
vote
3answers
405 views

What's a better alternative to this code?

Having read 'don't use query_posts', I've also read that it's ok to use 'for displaying a list of posts or custom-post-type posts on a page (using a page template), and you want to make pagination of ...
-1
votes
1answer
23 views

How to get custom post type posts with certain multiple tags names and category id?

Here is my query: $args = array( 'post_type' => 'jobs', 'cat' => $category_id, 'tag' => $searchval, 'paged' => $paged ); query_posts($args); But this not working.
0
votes
2answers
1k views

How to add <ul> in WP_Query to every 3 posts displayed? [duplicate]

I want to display every 3 products in a <ul> Example of how HTML should look: <ul> <li>product looping 1</li> <li>product looping 2</li> <li>...
0
votes
1answer
144 views

Random posts that always include a particular post?

How can I always include a post/ page in the random result? For instance, I always want to get 3 items only from my articles. But I want the result always has the article with page order 1: $...
0
votes
2answers
63 views

Get the amount of posts on a current page

I have loop and I want to get the amount of posts on a current page. So I try: <?php $post_number = $wp_query->post_count; ?> <?php echo($post_number) ; ?> <?php while ( have_posts()...
0
votes
0answers
41 views

Manipulate query to show specific post

I want to alter the (main?) WP query so it will show a specific post under set circumstances. I tried: add_action('pre_get_posts', 'a_b_c'); function a_b_c(&$query) { //When in admin menu, ...
0
votes
1answer
192 views

Unable to get specific value from post meta

I am using get_post_meta() to retrieve a custom meta field value from a given post. The custom meta box has a parent checkbox which has 3 child checkboxes. I want to get the values of both parent and ...
1
vote
2answers
661 views

Five posts from a category in footer

I am trying to show 5 posts from a category in my home footer. I have placed this code <?php query_posts( 'category_name=entertainment&posts_per_page=5' ); ?> right in my home.php file ...
0
votes
0answers
722 views

How to display products with multiple conditions, product_id and category_id

I want to show all product satisfy 2 conditional are array product id and array categories id . I tried this code but it's not working $args = array( 'post_type' => 'product', '...
0
votes
1answer
1k views

Display Posts on Custom Page

I have a custom page template created for my homepage. I have this set to the Static Homepage under the Reading settings. I want to be able to show the last three news posts from my Blog page which is ...
1
vote
2answers
2k views

Cannot Update A Post, 404 Error

After months of leaving and deleting my WordPress site, I decided to try again. I downloaded the new version 4.7.3, installed and added a new post. So far so good. I then went back to edit the post ...
0
votes
3answers
571 views

Posts from a category on homepage with category archieves page default css

I am trying to accomplish something. First am using two themes on my blog, on the mobile theme which is carrington, i would love to add five posts from a certain category or tag for example "Tech" to ...
0
votes
1answer
80 views

update a posts of other custom post type

i create a new custom post type which i named "invoice" and then i create an new custom post type named "car" which contained a field "Km traveled" i want to update the field of "km traveled" of post ...
0
votes
1answer
131 views

Querying posts from current category, using a variable as array argument

I been banging my head around on this one. I'm making a custom catagory template page, and I want to pull up all posts in the same category as stated in the URL (domain.com/category/example). But when ...
0
votes
1answer
71 views

WP Query Relations / Compare

I am trying to get the search query to use an 'OR' for these arguments. It is currently using 'AND' which I can not figure out how to change. I thought the line: $args['meta_query'] = array('...
1
vote
2answers
2k views

Display custom post type from dynamic custom field

I am trying to create a custom meta box that lets you add rows dynamically. Following code snippet works fine and and saves data in my edit page section. However, I can't get it to display the data on ...
2
votes
1answer
1k 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 ...
0
votes
1answer
18 views

Pull new posts using feed

How can I query new posts from a website using the RSS/ATOM feed? I mean how can I structure the query URL to do that (say bring me all new posts from the last 10 days)? Thank you
1
vote
1answer
630 views

Pagination is not working on single-{slug}.php but works fine on page-{slug}.php

I would like to have my single-{slug}.php perform a query on a list of posts from different custom post type and use pagination. The pagination appears but unfortunately, clicking the pagination does ...
2
votes
1answer
880 views

Separate Posts and Custom Post Type in Custom Taxonomy archive template

I have created both a Custom Post Type (Match) and Custom Taxonomy (Team), and have made the Team taxonomy available to normal posts (news for that team) and the Match custom post type. However, on ...
1
vote
2answers
420 views

Query/list all terms and their custom post count

I want to query/list all the terms (from all the custom taxonomies) within a custom post type with their custom post count. This is what I have so far... $the_query = new WP_Query( array( '...
0
votes
1answer
242 views

Wordpress post filter menu

Hi I am trying to create a form that filters my posts by 3 requirements, Categories, Author and Date. The user should be able to select a requirement from each dropdown (or leave empty for all) and ...
0
votes
1answer
37 views

function query_posts disabling current_page_menu class

I have a header and a footer menu (they're the same: Primary Menu). When I'm on a page, wordpress adds classes like current_page_menu. But on pages where I use the query_posts() function the menus ...
0
votes
1answer
649 views

Pagination not working on my archive page for a custom post type

First off I have a custom post type called events, and I wrote a custom query in in my archive-events.php file. Everything is working great except for the pagination. To trouble shoot I stripped ...
0
votes
1answer
41 views

Display custom post type by custom taxonomy

I've got a custom post type called "listing" a custom taxonomy called "listing_tags". I'd like to display the listing post type posts that have a listing_tag called "basic". Is this possible? I ...
0
votes
1answer
50 views

How to correctly escape data

I want to get recent posts and I use wp_get_recent_posts : <?php $args = array( 'numberposts' => '3', 'post_status' => 'publish', 'orderby' => 'rand' ); $recent_posts = ...
3
votes
1answer
519 views

Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]

The rewind_posts function is meant to be used when the loop is going to be called more than once in a page with the same query. If I call the same loop a second time in the page the result is the ...
4
votes
1answer
4k views

Get the number of posts from the current page results

I am trying to get the current number of posts that will be present in a page. $wp_query->found_posts will give me the total number of posts in the loop. get_query_var( 'posts_per_page' ) will ...
0
votes
0answers
307 views

Use special template for the first post in the loop

I want to use a special template for the first post in a loop. So I tried this: <?php while ( have_posts() ) : the_post(); if( $wp_query->current_post == 0 && !is_paged() ...
0
votes
1answer
1k views

Blog posts not displaying on blog posts page

Not sure what's happening, but I just took over a site, and no blog posts are rendering on the blog index page. Posts are displaying on the home page but not the posts page. Any suggestions to what ...
0
votes
2answers
11k views

How to limit post per page of custom post type?

Here's the codes i used to display the posts of my custom post "episode" <?php if( is_home() ){ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( array('post_type'=>...
1
vote
2answers
1k views

How to query 'posts_per_page' to display a different blog posts index template?

Trying to create a 'switching' blog template using home.php, controlled by 'Blog posts per page' setting in the admin area. If set to '1', it will show the single post template. Anything higher and it ...

1 2 3
4
5
24