Performance bug - slow DB query

Since 2017-09-26 I have terrible problems with performance on my website. Loading single post or any other page takes even 20s. I've been debugging it it found out, that the problems are DB queries. For example this one is executing almost with every page load and takes about 36s: SELECT t.*, tt.*, tr.object_id FROM az2_terms AS t INNER JOIN az2_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN az2_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('znacka', 'model') …
Category: Web

Using wp_list_table how to trigger update function "inline"?

Ok, i have used wp_list_table to read data from a custom db table and i like to be able to update the database table by clicking the correspondig cell. Defaults are 0 and when clicked the value is set to 1. so by clicking the cell updateVisitor() will be triggered "inline" my function which i isn't part of the Visitors extend WP_list_table class function updateVisitor($id){ global $wpdb; $query = $wpdb->prepare( "UPDATE tbl_visitor SET visitorPayed =BINARY(visitorPayed=1) WHERE visitorID = %d", intval($id) …
Category: Web

How to retrieve attachments from child pages of a specific Page?

How would I retrieve attachments from all subpages of a specific Page ID? Example: SPECIFIC PAGE Child (with attachments) Child (with attachments) Child (with attachments) I'm currently using this code to retrieve all attachments site-wide, however I would like to limit this to only pull images from all children of a specific Page. $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null ); $attachments = get_posts( $args ); if ( $attachments ) { foreach …
Category: Web

How to display a specific category using a custom Query in WordPress?

Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : global $wpdb; $posts = $wpdb->get_results( 'SELECT ID, post_title AS title, post_excerpt AS excerpt FROM '.$wpdb->posts.' WHERE post_type = "post" AND post_status = "publish" ORDER BY post_date DESC LIMIT 4' );
Category: Web

Query multiple post types, but different order for each

I have a query which searches 2 post types as below: $args = array( 'post_type' => ['post', 'promotion'], 'posts_per_page' => 12, 'paged' => $paged, 's' => isset($_GET['search']) ? $_GET['search'] : '', ); This orders them by default, by published date. I need to add a third post type events. This however needs to be sorted by a custom field event_date asc and to disregard those which the event_date is in the past. Does anyone have any suggestions on how this …
Category: Web

WP Search Form Query: Add Author's posts into search query

As the title suggests, I'm looking for WordPress advice relative to leveraging the standard searchform.php functionality to additionally query the author field when performing searches. I've tried various different means to do this without any success, and so I'm coming to quite the headache. Below are the template files used: searchform.php <?php /** * Template for displaying search forms in Twenty Seventeen * * @package WordPress * @subpackage Twenty_Seventeen * @since 1.0 * @version 1.0 */ ?> <?php $unique_id = …
Category: Web

Compare ACF date field (if exists) and post date and order DESC

I have an ACF date field (same format as post date) and in my Query I want it to be compared to the publish date of the post: If erstelldatum is not empty use erstelldatum for order If erstelldatum is empty use publish date for order instead Order descending My code is working so far but the order isn`t right. It lists all posts with erstelldatum first followed by those without. I want them to be ordered descending by the …
Category: Web

Create custom query for search?

I have create search box using ajax.If i enter any value in search input box that this value search in post title or post meta data and get all data of this value in custom post type.also query check only post title and specific post meta data. Not check in Post content or any other field. I have tried this query $args = array( 's' => $keyword, 'numberposts' => -1, 'post_type' => 'store', 'meta_query' => array( 'relation' => 'OR', array( …
Category: Web

How to set up hierarchical relationships without using plugins / meta query

I'm running a large database of musical artists and their releases. I inherited the site after it running for a long time. There are currently several different custom post types, created with a Toolset plugin. The post types are hierarchical like this Artists | Directors | Releases | Albums | Singles | Videos | Misc | Artists and Directors are parent to Releases, which is a parent to the Version Albums | Singles | Videos | Misc | are the …
Category: Web

How to add custom meta to 'pre_get_terms'?

I have a custom taxonomy with custom meta. I have added the custom meta values to columns in the admin list page just fine. But if I search for values that are in these columns nothing is found. I'm assuming I need to use pre_get_terms, but am having trouble figuring out how to include the meta in the query. Here is what I am trying to do to test one of the fields, but results are still negative. add_action( 'pre_get_terms', …
Category: Web

Comment Table Size Results in Slow Page Loads and 500 Errors

I manage a small site that has a very active comment area. The site is on shared hosting. There is a daily post entry, then a robust comment area. It is not untypical to have more than 100 comments on a day's post. The result is that loading or refreshing the current day's page is very slow - up to or more than 30 seconds. Sometimes a page load will time out with a 500 error. Other times a comment …
Category: Web

Show first posts with custom field not empty and order all by title

I have a custom post type called "products". My goal is to make my custom query that I have on homepage and also the search query show first the posts that have a custom field called "id_number" not empty and then the other posts that have the "id_number" empty. All should be ordered by title. This is my code so far only for my custom query. I also need it for search page query but I didn't get that far. …
Category: Web

wpdb get_results() returns only 2 rows

I am trying to create custom admin widget to present how many users has registered within last days. I have created function as below: function mdbootstrap_add_dashboard_recent_users(){ global $wpdb; $query = " SELECT count(*) as counter, DATE(wp_users.user_registered) as regdate FROM wp_users GROUP BY DATE(wp_users.user_registered) ORDER BY DATE(wp_users.user_registered) desc"; $posts = $wpdb->get_results($query,OBJECT); print_r( $posts); } However for some reason it's returning only 2 rows: Array ( [0] => stdClass Object ( [counter] => 1 [regdate] => 2016-01-12 ) [1] => stdClass Object …
Category: Web

Get all comments of author's posts

Hello I have multi author website. I want to display all comments of posts created by author in author page. Please help me. I found this code but fatal error <?php $args = array( 'author' => AUTHOR_ID, 'posts_per_page' => 500, //Don't use -1 here ); $the_query = new WP_Query( $args ); if($the_query->have_posts() ) : ?> <?php while ( $the_query->have_posts() ) : ?> <?php $nested_args = array( 'post_id' => get_the_ID() ); $comments_query = new WP_Comment_Query; $comments = $comments_query->query( $nested_args ); if …
Category: Web

What is the best way to cache pages on Wordpress

I have a site with many custom queries. Some take many seconds to load a page. To solve that issue, I have been using a caching plugin. The issue is, my caching plugin does not cache a page until I click it once. I'd prefer to do this entire process without a plugin if possible. If the plugin route is the best way to go, I'd love to know that too. I have an idea that this is how it …
Category: Web

How to run select query of post with category and tags?

I want to fetch multiple posts with categories and tags currently I'm using this query: $pagesize = 20; $pageNumber = 1; $mysql = mysqli_query($con,"SELECT p.post_title, p.ID, p.post_content, p.post_date, p.post_name as url, t.name as category_name FROM wp_posts p, wp_terms t, wp_term_relationships r, wp_term_taxonomy tt WHERE p.post_status='publish' AND tt.taxonomy = 'post_tag' AND p.id=r.object_id AND r.term_taxonomy_id=tt.term_taxonomy_id AND tt.term_id = t.term_id ORDER BY p.post_date desc LIMIT ".(int)($pageNumber*$pageSize).",".(int)$pageSize."") or die ("error".mysqli_error($con)); The mysqli-connection works. But when I run this code, I only get a blank …
Category: Web

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 permalinks, given the fact that I don't have access to the ID's to use post__in with WP_Query.
Category: Web

Exclude post from wp_query based on custom field boolean

I am trying to give users an option to select "Exclude from homepage bloglist" on a post, and then pick this up on my homepage query so certain posts won't surface on the homepage. I'm using the Wordpress custom field "true/false". On a post where the box has been ticked, I would assume this post would then not surface on the homepage based on the below query args: $query_args = array( 'meta_query' => array( 'key' => 'exclude_from_homepage_bloglist', 'value' => false …
Category: Web

How to get comment images stored as serialized comment meta

I want to display images under for each comment but images store in database as serialized a:3:{i:0;i:775;i:1;i:776;i:2;i:777;} I wrote this code print_r (get_comment_meta( $comment->comment_ID , 'reviews-images', true )); but it outputs this * Array ( [0] => 778 [1] => 779 [2] => 780 [3] => 781 [4] => 782 ) 10 then I tried this echo get_comment_meta( $comment->comment_ID, 'reviews-images', true ); not worked . Please help how can I get image urls instead of this output
Category: Web

custom query to get posts

I want to create custom links like mydomain.com/custom_page/cat=ABC&tag=XYZ So that when a user clicks on the link s/he can see all posts in the category 'ABC' having tag 'XYZ' For this I've created a custom template with the following code <?php /* Template Name: MyCustomTemplate */ ?> <?php get_header(); ?> global $wp_query; get_query_var( 'cat' ); get_query_var( 'tag' ); <?php get_footer(); ?> I don't know how to query for the posts in the category 'ABC' with the tag 'XYZ' I checked …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.