Counting Search results, and displaying the offset per page

I’m afraid you’re doing it a little bit wrong… Here are the problems: post_count field contains the number of posts being displayed and not the offset. wp_count_posts returns the number of posts globally, not in current query (so it will not be true for queries that have some filters). echo $post_count; . ‘-‘ . $post_count; … Read more

Woocommerce Email attachments not working – file not being attached

Apparently Woocommerce need a local path and not a URL to the file. In order to fix I used this: function attach_order_notice ( $attachments, $email_id, $order ) { // Only for “New Order” email notification (for admin) //if( $email_id == ‘new_order’ ){ $file_path = wp_upload_dir()[‘path’]; $file_name = get_field( ’email_file_attachment’, ‘options’ )[‘filename’]; $attachments[] = $file_path . … Read more

Sending a custom form data in email through WP Mail Function

I would suggest using AJAX for this. You could do something like this for the jQuery part: <script type=”text/javascript”> jQuery(document).ready(function($) { // Execute when user clicks on the “Submit” button $(‘#SUBMIT_BUTTON_ID’).on(‘click’, function(e) { e.preventDefault(); var email = $(‘input[name=email]’).val(); var firstname = $(‘input[name=firstname]’).val(); var familyname = $(‘input[name=familyname]’).val(); var other_names = $(‘input[name=other_names]’).val(); var dob_day = $(‘input[name=dob_day]’).val(); var … Read more

How can I group posts by months and years?

You can do it like so: global $post; $posts = get_posts( array( ‘post_type’ => ‘press’, ‘nopaging’ => true, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // it’s DESC; not DSC // There’s no use setting posts_per_page when nopaging is enabled. // Because posts_per_page will be ignored when nopaging is enabled. ) ); $_year_mon = ”; // … Read more

Issue with php version 7.2 in running search

I’m going to guess that PHP’s settings have changed with the upgrade. Division by zero suggests some variable is not initialized (and is being dynamically typed as 0). The PHP manual has a lot of information on the changes between 5.x and 7.x. This bit on how variables are handled supports my hypothesis, especially if … Read more

update_post_meta on multi-dimensional array options

You can’t, get_post_meta and its associated APIs all work on key/value pairs, you can update the value, but you can’t update a sub-section of it. You have to retrieve the entire value, modify it, then put it back as a whole. Additionally, values are always strings, so to make this work WordPress will PHP serialize … Read more

What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?

PHP is running on the server, JavaScript in the client. This means PHP is faster (more resources), the result can be cached, and you have to test only one interpreter. JavaScript – you don’t really need jQuery for this – is more error prone, because of weird clients, blocked resources, or a more limited available … Read more

get taxonomy thumbnail and use it as a variable in code

You have ‘taxonomy’ => ‘product_cat’ in your code, so most likely you have Woocommerce, and we need to get a category picture from there. Try this code <?php $args = array( ‘taxonomy’ => ‘product_cat’, ‘title_li’ => ”, ‘hide_empty’ => 0, ‘echo’ => 0, ‘show_count’ => 0, ‘style’ => ”, ‘parent’ => 0 ); $get_cats = … Read more