Add up all numbers from a WordPress query [closed]

.= does string concatention, eg, ‘hello ‘ . ‘world’ gets you hello world. To add, use + instead of .: // Set a default for $numbers. $numbers = 0; $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); $party_size = get_field(‘reservation_party_size’, $post_id); $numbers += intval( $party_size ); } } return … Read more

Is it possible to remove the “Shop” title from the WooCommerce catalogue? [closed]

CSS METHOD To hide with CSS this should do the trick for you. Add the following to the theme’s or child theme’s style.css, or to the Customizer’s CSS section: body.post-type-archive-product .bs-card-box.page-entry-title { display: none; } What we’re doing here is targeting the product archive template file that WooCommerce uses to dynamically create that page. By … Read more

Hide ID for WordPress User Role Subscriber

You can use the body_class filter and the wp_get_current_user() function to add the current user’s role to the <body> element, and then hide your elements with that (untested): add_filter( ‘body_class’, static function ( $classes ) { $user = wp_get_current_user(); $roles = $user->roles; if ( ! is_array( $roles ) ) { $roles = array( ‘subscriber’ ); … Read more

Is there a way to get a path to the theme directory without the server name?

Yes get_template_directory: get_template_directory(): string Retrieves template directory path for the active theme. Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI. In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory. To … Read more

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

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.