Duplicating Table of Contents for Paginated Post

You split post content into multiple pages with <!–nextpage–>, so you can use $page_number = get_query_var( ‘page’ ) to get current page number and global variable $numpages to get the number of pages in current post. Displaying table of content: global $numpages; $post_link = get_permalink(); $page_number = get_query_var( ‘page’ ); $toc = [ 1=>’Introduction’, ‘I2C … Read more

Add Custom Field to a template page backend

You need to create metabox (contains custom fields with a form) for your post/page or custom post type. When you use your code block above, you only call for meta values of post. But if WordPress can’t find any custom field or meta value, these variables retun null (and you can not see any value) … Read more

Conditionally hide or show woocommerce product variation in fontend by custom field

I ultimately solved this by manipulating the $options array. See full code below for conditionally hiding a product variation by a custom field, and display variations as radio buttons. Solution marked with comments /** * Convert WooCommerce variation dropdown to radio buttons. * * @param string $html Original dropdown html. * @param array $args Arguments. … Read more

Confusion regarding Nonce & using it in Custom Columns for Saving Checkbox Value to Post Meta

When trying to create a custom metabox, adding custom columns, managing custom columns and finally saving the post. Where do we need to pass the nonce. To make my question clearer. This is not correct, you shouldn’t need a nonce in a metabox because all that information is sent at once in the full request … Read more

Print terms with taxonomy and metabox value

Try This: $args = array( ‘hide_empty’ => false, ‘relation’ => ‘OR’, array( ‘key’ => ‘serial_language’, ‘value’ =>’english’, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘serial_language’, ‘value’ =>’arabic’, ‘compare’ => ‘LIKE’ ), ‘taxonomy’ => ‘serial’, ); $terms = get_terms( $args ); hope this will help

tracking number field in Woocommerce order [closed]

The syntax to get your custom field is: get_post_meta($post_id, $key, $single); In your context, you should try: $tracking_id = get_post_meta($order->get_order_number(), ‘Tracking_ID’, true); To show you in your example: <?php /* translators: %s: Site title */ $tracking_id = get_post_meta($order->get_order_number(), ‘Tracking_ID’, true); ?> <p><?php printf( esc_html__( ‘Your %s order is completed. Your tracking number is: %s’, ‘woocommerce’ … Read more

two custom fields question

All you have to do to hide this link is to check, if it’s empty: <?php if ( $link = get_post_meta($post->ID, ‘mp3_link1’, true) && trim($link) ) : ?> <a href=”https://wordpress.stackexchange.com/questions/326188/<?php echo esc_attr($link); ?>” target=”_blank”>MP3</a> <?php endif; ?>

How to create shortcode to display custom field value on a custom post type

You’ll have to use add_shortcode to achieve this. Let’s say that you want this shortcode to be called “my_cf”: function my_cf_shortcode_callback( $atts ) { $atts = shortcode_atts( array( ‘post_id’ => get_the_ID(), ), $atts, ‘my_cf’ ); return get_post_meta( $atts[‘post_id’], <FIELD_NAME>, true ); } add_shortcode( ‘my_cf’, ‘my_cf_shortcode_callback’ ); Now you can use it by putting [my_cf] or … Read more