Adding widgets with Featured Image via the Customizer run hundreds of queries

The issue boils down to this bit of code in WP_Widget::display_callback(): $was_cache_addition_suspended = wp_suspend_cache_addition(); if ( $this->is_preview() && ! $was_cache_addition_suspended ) { wp_suspend_cache_addition( true ); } This gets called right before WP_Widget_Recent_Posts::widget() and its purpose is to try as best as possible for back-compat to prevent widgets previewed in the Customizer from polluting the object … Read more

Widget for adding HTML markup to a page

If you want to do it the “WordPress-way”, you would create a custom post-type for books called “book” ( For this take a look at https://codex.wordpress.org/Function_Reference/register_post_type ). Then you would create an archive page for that post-type called “archive-book.php”. I hope this helps a little bit. If you need more help, let me know.

Custom Post Type Loop throws 500 error when used in widget

There are several problems in your provided code. $query -> while( have_posts() ) The WP_Query() return type is object. You are referring to a method that doesn’t exist. Instead, you should use the following: while( $query->have_posts() ) {…} wp_reset_postdata(); inside the conditional This function resets the post’s data, as it suggests. If you use it … Read more

Inject widgets from one sidebar into another with PHP

Here’s an (untested) idea where we inject the sidebar-inject sidebar before sidebar-target sidebar with help of the dynamic_sidebar_before hook : add_action( ‘dynamic_sidebar_before’, ‘wpse_inject_sidebar’, 10, 2 ); function wpse_inject_sidebar( $index, $has_widgets ) { // Only target front-end if( is_admin() ) return; // Only target ‘sidebar-target’ if( ‘sidebar-target’ !== $index ) return; // Make sure ‘sidebar-inject’ is … Read more

Recent Posts – Show all posts

Under settings you can control how many posts there are, you can’t set -1 which would be unlimited posts, but you can set a very high number: But What About just The Homepage? A lot of people get around this by putting a custom query in their homepage template, but those people are doubling the … Read more

Add field to dashboard to update embedded URL on homepage?

Add the below code in the functions.php file and it will create a text field in the general setting options page add_action(‘admin_init’, ’embed_url_initialize’); function embed_url_initialize() { // First, we register a section. This is necessary since all future options must belong to one. add_settings_section( ‘general_settings_section’, // ID used to identify this section and with which … Read more