Questions tagged [query]

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

3
votes
0answers
145 views

wp_enqueue_media() slows down my WP site

My website's been incredibly slow and I installed the query monitor plugin to learn more about the issues that caused this. When loading "New post" page, the following query takes 7,3662 (seconds?!) ...
3
votes
0answers
77 views

my function doesn't return my post from today

I'm using gravity form to create some custom post type - as events. Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great. However, I ...
2
votes
0answers
322 views

Search query - exact post title match

I have a bunch of posts titled something like this... English Language 2015 English Language 2016 English Language 2017 English Language 2018 And on each one of these posts I have a dropdown select ...
2
votes
0answers
793 views

How to remove duplicate query on page load or make them cacheable

I'm having the same issue as Lletnek where there are the same duplicate queries for get_page_by_path on some of the pages on our website. I have got the queries down to 2/3 on most pages using ...
2
votes
0answers
71 views

Sorting posts alphabetical that have single digits

I have post titles that are like this: Episode 1 Episode 2 Episode 6 Episode 10 Episode 14 I try to list posts alphabetically but it ends up showing like this: Episode 1 Episode 10 Episode 14 ...
1
vote
0answers
28 views

get search results from only specific page name in wordpress

I have created a page by using add_submenu_page: add_submenu_page( "pharma-plugin", // parent slug "All Trade Name", // page title "All Trade Name", // menu title "manage_options", // ...
1
vote
0answers
149 views

Filter posts in category archive page by year using a dropdown

I'm trying to filter my posts by year in different categories by changing the query using a dropdown with this code: <form method="post" action=""> <...
1
vote
0answers
49 views

How do I use AJAX Query in my posts loop?

I have this function in my functions.php. All the AJAX and Query is working but displays the results of the loop right below the AJAX filter. I want the query loop to display in my main theme's ...
1
vote
0answers
65 views

wpdb->term_taxonomy count posts from both published and private posts?

I'm trying to understand why this query won't include both private and published posts when counting and sorting the taxonomy terms. $taxonomyTypes = "AND ( tax.taxonomy = '" . ...
1
vote
0answers
21 views

Query posts intersecting tags and categories

if I have category 'catname' and tag 'tagname' is it possible to visit for example site.ext/catname/tagname and query all posts that are contained in specific category 'catname' and specific tag '...
1
vote
0answers
54 views

Form redirect with query vars to page

EDIT: SOLVED query var and custom post type had the same name story This has been bugging me for few hours so any help is appreciated. I am building a theme, and I have a page named edit-story ...
1
vote
0answers
142 views

Long running queries

I'm trying to build a PHP script that will pull the 10 most read posts (weekly) and will return me an XML file (so I can link it to Mailchimp). Im also using - Post Views Stats Wordpress plugin by ...
1
vote
0answers
290 views

$wpdb->replace: WHERE?

My plan is to upsert values in a custom meta table with $wpdb->replace. This is what I try: $up_meta = $wpdb->replace( 'spieldaten', array( 'spiel_uid' => $uid, '...
1
vote
0answers
71 views

wpdb php get_var query to get ID for URL image doesn't work for ID over 999

I have been using the following php code in a custom plugin to successfully capture the image ID for a media image URL in Wordpress global $wpdb; $picture_ID = $wpdb->get_var($wpdb->prepare(...
1
vote
0answers
473 views

filter RSS feed in URL

I have been busy with RSS feeds lately so I can auto load my content in my email service. I have build a feed (which works) and inside the feed I can toggle preferences by filtering on categories, ...
1
vote
0answers
75 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('...
1
vote
0answers
115 views

Issue with using add_rewrite_rule() for post querying custom fields

Here's what I'm trying to do. I made it so that the posts can store a postmeta value using a meta box textarea field. Here's what I have done so far: I extract the meta value and explode it to an ...
1
vote
0answers
108 views

wp_query get post custom taxonomy in search.php

domain.com/?cat=id custom taxonomy not get post but category get to post How do you write wp_query get post taxonomy? <?php $args_my_query = array( 'post_type' => 'post', '...
1
vote
0answers
42 views

Group custom post listing in admin section

I am trying to alter the listing results in the admin section for a custom post type. I am using Custom Post Type UI plugin to create custom post types and data is saved with meta keys. The listing ...
1
vote
0answers
130 views

Two queries for a WP_User_Query search work perfectly apart, but not together

I'm putting together a page that pulls User data and displays it in an attractive social-media-like format. I want to use a variable passed in through an input on the site to search multiple fields, ...
1
vote
0answers
62 views

Form and custom query problem

I'v a form and custom query to find product from specific category. When I launch search, the product is deleted instead of being retained. How to correct this ? thanks <!-- Add search product for ...
1
vote
0answers
634 views

Export Specific User data without plugin

I need to export a list of site users to a csv/xlsx file. I am creating an admin page with a download button which should run the export function. I need to export the following data from wp_users: ...
1
vote
0answers
42 views

Query in query for Widget

I have the following code that works on a page, for listing attachments that are set in a 'folder' by folder ID using another plugin. but when I try to place this in my widget code, it doesn't work. $...
1
vote
0answers
66 views

WP_Query with 'rand', but equal number of posts from the taxonomy terms given

I have two terms in a taxonomy that I'm attempting to fetch equal amounts of posts from. Of course, if the posts_per_page is an odd number, I wouldn't get a truly "equal" number of posts; but we can ...
1
vote
0answers
46 views

WordPress custom setting page - add flashing message

I have a custom settings page for my plugin that has in the same page a submit button and a link like http://mysite.dev/wp-admin/options-general.php?page=my-page&action=update-cache&_wpnonce=...
1
vote
0answers
676 views

Create Indexes for Slow Queries

I've gathered that I may be able to solve my slow query problems on a WordPress site with over 200k posts by using indexes. Hoping someone could help explain some. SELECT SQL_CALC_FOUND_ROWS wp_posts....
1
vote
0answers
105 views

Multisite pagination issue by multi query archive 404

Im using https://github.com/miguelpeixe/WP_Query_Multisite to collect posts to the mainsite from others. My archive page is $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $...
1
vote
0answers
47 views

get the taxonomies terms associated with users

I’m building a search form with meta_query to get users based on meta_key and meta_value. Some meta_key are taxonomies. It works very well but in my select, i have all terms and some terms are not ...
1
vote
0answers
31 views

Alter main archive, to show posts with meta as last

I'm having troubles with getting posts with meta_value "sold" as last in the main query of my custom Post type. The best/easiest way i can think of at the moment is to filter the "sold" posts out of ...
1
vote
0answers
29 views

Query with relation and one without relation using multiple taxonomies?

I'm trying to use one query for two queries, one with an and relation and one without without having to do multiple queries and loops, is this possible? <?php $args = array( 'post_type' =>...
1
vote
0answers
89 views

Prioritize posts in query by meta keys?

I have a CPT called jobs. In my single jobs page I am counting page views with these functions: /********* Post Views counter ***********/ remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head',...
1
vote
0answers
79 views

Query to get number of posts last week

I want to receive each monday the number of posts that were posted on my site during the week. The first part of the code retrieves the number of posts, and the second part sends me an email with the ...
1
vote
0answers
100 views

Query if audio attachment AND/OR custom field

I've been trying several things but to no avail... Searched, maybe not good enough though! I have posts that either have an uploaded audio file AND/OR has a Soundcloud link (which is a custom field). ...
1
vote
0answers
246 views

How to query all posts of a specific category, and any other category combination

Basically, I'm looking to query all post of category 'news', and any combination of other categories to display as Related News on single content type pages. So, if someone writes a post, and ...
1
vote
0answers
1k views

Include data from custom table in WP_Query

I'm building an Estate Agent website. They have a system where they add their available properties and sends them all to the main property portals. As part of this, the system also sends all the ...
1
vote
0answers
1k views

SQL query equivalent to WP User Query

I have the following WP user query code: //Get all users sorted by whatever $sorted_users = new WP_User_Query(array( 'orderby' => 'meta_value', 'meta_key' => 'satisfaction_rating', '...
1
vote
0answers
795 views

Using $wpdb (WPDB class) 'replace' with multiple WHERE criteria problem

I have two fields that are used to identify a particular row (acting as a composite key). If it does not exist, I wish to insert a new row. The REPLACE function (http://codex.wordpress.org/...
1
vote
0answers
1k views

WP_Query orderby and tax_query

My goal is to have custom posts type's posts (CPT for simplicity) from a custom taxonomy (CT for simplicity) let say CT Hometown with slug Nebraska to be listed grouped by another CT, let say ...
1
vote
0answers
1k views

Slow meta_query with about 4 milion record on wp_postmeta

Although optimized wordpress all the way but still very slow as follows : I have converted from LONGTEXT meta_value field to TEXT Then create INDEX for this field ALTER TABLE wp_postmeta ADD INDEX ...
1
vote
0answers
3k views

How to get latest posts from each category in regular order

let's say I have a main query and it displays posts from Movies and Music categories. I want the query to show always 5 latest posts from Movies and 5 latest posts from Music category. When I create a ...
1
vote
0answers
27 views

Order posts with a custom field but also without

I am querying and ordering posts with this code but my theme adds the custom field (cb_vote_nb_vote) only if someone clicks the "vote" button, since I am doing a listing, posts created without that ...
1
vote
0answers
82 views

How Can I Put Meta_Compare in the Database-Query?

Yes, I know that this can easily be done with built in wp_query but I need this in Wpdb query. I have a custom field and I need to display posts where this field does not exist. By the way can I get ...
1
vote
0answers
98 views

Query posts dynamic date range

So, I'm using the following to filter posts: $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' ); $args['paged'] = $paged; ...
1
vote
0answers
155 views

Caption and title in img alt tag are the same?

I'm currently on WP 3.6 and noticed an unpredictable behaviour with the alt attributes generated by WP. If I have an image title, the title appears in the alt. If I have a caption, the caption ...
1
vote
0answers
175 views

Post 2 Post Site Search

I'm trying to filter search terms bases on categorisation created by posts 2 posts. I'm using the generic site search and then I've created a search filter function my_filter_the_search($query){ ...
1
vote
0answers
189 views

Wordpress Query orderby title with UTF8 string in title

I got posts with titles are in utf8 encoding. When I query posts with orderby is title, those with utf8 characters at the beginning are at the end. Example: post title starts with Đ are at the end ...
1
vote
0answers
91 views

Sorting main query by custom taxonomy slug

Is there a way to sort posts by custom taxonomy (shoe_color) ASC|DESC? I would like to do this using query_posts and passing the orderby=shoe_color into it. Here is the code I'm trying to work out: ...
1
vote
0answers
306 views

get_query_var('paged') giving same result

I have a custom page, in that page i am using a custom select query for my search functionality. The problem is pagination not working. I used $on_page= get_query_var('paged'); for pagination. When ...
1
vote
0answers
174 views

Changing status of Published posts which have less Content to “Draft”

function draftpost(){ global $wpdb; $prefix = $wpdb->prefix; $wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) <500"); } add_action('...
1
vote
0answers
559 views

WordPress Query wp-terms SLOW

I've got a very large database in WordPress with lots of products in WooCommerce along with quite a bit of taxonomies. When querying the products on the front end it takes 1 minute or more. Here is ...