Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder

There are 2 places that could have issues: Your first wpdb::prepare() here: // Prepare and execute the count query $count_query = $wpdb->prepare( $count_sql, …$query_params ); The initial value you set for $count_sql is “SELECT COUNT(*) FROM $table_name WHERE 1=1”, and if $filters doesn’t have any key matching your switch, the value of $count_sql will remain … Read more

PHP Deprecated function Optional parameter $function

At your function declaration you need to set the required parameters first, the optional second, because you couldn’t skip $function if $page has to be given: function add_meta_box($id, $title, $page, $function = ”, $context=”advanced”, $priority = ‘default’): void { require_once(ABSPATH . ‘wp-admin/includes/template.php’); add_meta_box($id, $title, array(&$this, $function == ” ? $id : $function), $page, $context, $priority); … Read more

Split titles by the ” – ” in WordPress

i’ve already solved it, i had to change the $title = get_the_title(); to $title = get_post()->post_title; in the end it looks like that: <?php $title = get_post()->post_title; // Get the title string $parts = explode(‘ – ‘, str_replace(‘–’, ‘-‘, $title)); // Replace em dash with en dash and split the title $artist = trim($parts[0]); // … Read more

Adding a variable to some PHP code with gettext

Use sprintf(): // Translators: %s: author’s current year. esc_html( sprintf( __(‘Rates %s in &euro;/ week:’,’mysite-plugin’), $current_year ) ); This is a common pattern that can be found in WordPress core. The Translators: comment is also essential to provide translators with context to translate the passage and understand what the placeholder %s will contain.

Upgraded php & wordpress but theme broke

<?php the_post_thumbnail(thumbnail); ?> should be <?php the_post_thumbnail( “thumbnail” ); ?>. thumbnail is not a defined constant, and the updated version of PHP is no longer converting undefined constants into strings for you. It appears that PHP changed the “undefined constants” message from a notice to a fatal error sometime around version 8.

Unable to remove action from parent theme via child theme

The child theme’s functions.php is loaded before the parent theme’s functions.php: Unlike templates and patterns, the functions.php file of a child theme does not override the functions.php file in the parent theme. In fact, they are both loaded, with the child being loaded immediately before the parent. Source: https://developer.wordpress.org/themes/advanced-topics/child-themes/#using-functions-php This means that when the child … Read more

“Cannot start session when headers already sent” when attempting session

It turns out not all hosts treat sessions alike. I ended up scraping altogether the “session” code in functions.php previously referred to which was doing nothing. Instead, I added session_start() at the top of every template adding or retrieving a value from a name/value hash in $_SESSION. So, <?php session_start(); $_SESSION[‘order_id’] = $order_id; . . … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)