How to modify wp_query to only return the data you need from the database. This can speed up your site when the database get's larger.
Here is a nice tip when you would like to speed up your database query for a given page. When you make a query for certain specific data in WordPress, WordPress by default will return ALL the data in an object. 95% of the time it is not required to return all the data from the database. It will just make your page loading slow especially if you have a WordPress Database that has taken on some fat. What you want WordPress to do is to STOP when it found the number of sufficient data/rows and not run around like a headless chicken on a black Friday sale collecting everything it possibly can. Inside the WP_Query CLASS, class-wp-query.php(line 684) there exist a argument to assit with this:
@type bool $no_found_rows Whether to skip counting the total rows found. Enabling can improve performance. Default false.
Extraction from the code inside the class-wp-query.php where it test to see if the option was set when the query was passed.:
Line: 1806// If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present.if ( isset($q['no_found_rows']) )$q['no_found_rows'] = (bool) $q['no_found_rows'];else$q['no_found_rows'] = false;public function parse_query( $query = '' ) ...
How to dynamically add shortcodes to multiple pages. This saves having to add shortcodes to potentially thousands of pages manually.
Here is a code example of how to add shortcodes dynamically to a WordPress Post or Page. Why do you want to do this? It happened that I had a request from a client to only show an introduction part of the description section and hide the rest with a “read more” feature. I found this plugin called “WP show more” on the WordPress repository that is able to hide certain parts of content if the content is wrapped inside the plugin’s shortcodes.
For example, to hide the second paragraph to conserve space you need to add the shortcodes before and after the second paragraph.:
Pellentesque elementum interdum nibh blandit scelerisque. Praesent in nibh eu odio finibus ultricies. Sed sit amet placerat justo. Quisque nec diam ultrices, molestie felis ac, convallis augue. Pellentesque euismod mauris at leo feugiat interdum. Praesent tempor lorem eget erat vulputate varius. Aliquam eget cursus nulla. Suspendisse potenti. Integer placerat augue magna, ac pellentesque ante finibus non. Sed vitae eros convallis, imperdiet massa ultrices, placerat nisi.
Vivamus orci erat, dictum vitae ultrices at, interdum tempus ex. Proin varius sodales vestibulum. Etiam pulvinar
I missed using Markdown, so I explored what options were available for using Markdown in WordPress posts. In this article I evaluate the options I found for using Markdown with WordPress.
Something I really like about developing with other languages / frameworks is that many of them have servers built in. This is very convenient, so it was frustrating not having this with WordPress. Over the years I have run WordPress in many different ways, MAMP, MAMP Pro, LAMP, XAMPP, Flywheel, Vagrant, Docker etc. But all methods I’ve used have had issues where I have had to spend a lot of times troubleshooting it. The built in servers that Ruby, Jekyll etc have make local dev simple and quick. You can get on with the actual coding and not focus to much on the server stuff.
But PHP does have a inbuilt PHP server, since 5.4.0, it just doesn’t get mentioned very much. It’s actually a great way of running a local install of WordPress when you don’t need bells and whistles, when all you need is a basic WordPress install.
You’ll need PHP and MySQL
All you need is PHP installed and a MySQL server running, which I won’t cover in this tutorial, since it’s is platform specific. So from here on, I’m going to assume from here that you have them installed. Google it and come back when your setup.
To check what you already have installed, type or