How to get the POST TITLE using the POST ID?

WordPress has a ton of the get_the_*() functions which you can pass an ID and return a value you’re looking for. In this case you can call get_the_title() which returns the title of a post. An example could look like: echo get_the_title( 3249 );

Function set default image when image not present

You’d want to put the <img/> tag and all the necessary content for the default image after the final colon in the following line: $my_image = ( $image[0] != ” ) ? ‘ <img alt=”‘ . esc_attr( sprintf( the_title_attribute( ‘echo=0’ ) ) ) . ‘” title=”‘ . esc_attr( sprintf( the_title_attribute( ‘echo=0’ ) ) ) . … Read more

Woocommerce add to cart quantity buttons with AJAX

I fixed it with some IDs add in function.php add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘quantity_inputs_for_loop_ajax_add_to_cart’, 10, 2 ); function quantity_inputs_for_loop_ajax_add_to_cart( $html, $product ) { if ( $product && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) { // Get the necessary classes $class = implode( ‘ ‘, array_filter( array( ‘button’, ‘product_type_’ . $product->get_type(), $product->is_purchasable() && … Read more

Change sign up fee in cart for subscription products WooCommerce

add_action( ‘woocommerce_before_calculate_totals’, ‘change_subscription_signup_fee’, 1000, 1 ); function change_subscription_signup_fee( $cart ) { if (is_admin() && !defined(‘DOING_AJAX’)) return; if ( did_action( ‘woocommerce_before_calculate_totals’ ) >= 2 ) return; // Loop through cart items foreach ( $cart->get_cart() as $cart_item ) { // Check that product custom cart item data “alredy_have_number” exist and is true if( isset($cart_item[‘alredy_have_number’]) && $cart_item[‘alredy_have_number’] ) … Read more

How to get specific image in media library with php

There’s a few functions: wp_get_attachment_image_url( $attachment_id, $size ) – Gets the URL to specified size of the image. wp_get_attachment_image_src( $attachment_id, $size ) – Gets an array of the image URL, width, and height for the specified size of the image. wp_get_attachment_image( $attachment_id, $size ) – Gets the full HTML for an image, including width, height, … Read more

How to query for pages/post depending on slug?

With a custom Page (post type page) and a custom Page Template, you can do it like so: In the templates, make a new instance of WP_Query which is used for querying the posts in either the Romanian or English language. In the query/function args for WP_Query and wp_get_archives(), use a custom parameter named lang … Read more