Link for Most Recent Post

You’ll need to use get_posts() to get the latest post, then pass it to get_the_permalink() to get the URL to it: <?php $latest_posts = get_posts( array( ‘numberposts’ => 1 ) ); if ( ! empty( $latest_posts ) ) : $latest_post = $latest_posts[0]; if ( $latest_post->ID !== get_the_ID() ) : ?> <a href=”https://wordpress.stackexchange.com/questions/284553/<?php echo get_the_permalink( $latest_post … Read more

How to Fetch values from WP database based on selected option value by onchange using PHP?

You can use below example to use Ajax in wordpress. This article explains it quite nicely. Main jquery function to use wp_enqueue_script( ‘ajax-scripts’, url-to-your-file/plugin-ajax.js’, __FILE__ ) , array( ‘jquery’ ), ‘1.0.0’, true ); jQuery(function($) { $(document).ready(function(){ $(‘#mySelect’).on( ‘change’ , function(){ var newValue = $(this).val(); $.ajax({ type: ‘POST’, url: ajaxurl, // use ajax_params.ajax_url if using in … Read more

Update Option Error: Notice: Undefined index

This is because when a checkbox isn’t checked it didn’t send to the server. This is why the POST array doesn’t have the upo_enable index. You can, however, check if the value is empty or not: $upo_enable = !empty($_POST[‘upo_enable’]) ? true : false; Or $upo_enable = !empty($_POST[‘upo_enable’]) ? $_POST[‘upo_enable’] : false; More on this: https://www.w3.org/TR/html401/interact/forms.html … Read more

Calculations in functions.php [closed]

On those lines get_post_meta() will return an array because by default the third argument of get_post_meta() is false. If you want to return a single value you should call it like so: get_post_meta( get_the_ID(), ‘invoice_service_amount’, true ); Additionally, you may want to get the post meta first and then ensure you have a value (wrapping … Read more

Correct syntax to html php conversion

you are missing the three curly brackets in before wp_reset_postdata(). backup your code and replace with this. <?php $args = array(‘post_type’ => ‘menu’, ‘posts_per_page’ => 5, ‘post__in’ => $ids, ‘post_status’ => ‘any’, ‘orderby’ => ‘post__in’); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); if (is_page(538) ) … Read more

Multiple choice in a custom taxonomy

To display multiple authors, loop through the array of authors: function show_product_autor(){ $authors = wp_get_post_terms( get_the_ID(), ‘autor’ ); foreach($authors as $author) { $authorTeamPg = get_page_by_title( $author->name, ‘OBJECT’, ‘team’ ); $authorTeamPgLink = get_permalink( $authorTeamPg->ID); echo “<b>AUTOR: </b><a href=”https://wordpress.stackexchange.com/questions/289422/{$authorTeamPgLink}”>{$author->name}</a>”,'<br />’; } } To handle editors, the simplest solution IMO would be to make the taxonomy heirarchical and … Read more

Ajax return code 400

Here’s a base snippet I use for AJAX submits in WordPress, it might help you out: <?php if (isset($_POST[‘my_theme_ajax_submit’])) if ( wp_verify_nonce( $_POST[‘nonce’], ‘my_theme_ajax_submit’ ) ) my_theme_ajax_submit(); function my_theme_ajax_submit() { // do something // some php code that fires from AJAX click of #fire wp_mail( ‘[email protected]’, ‘my_theme_ajax_submit() fired’, time()); wp_die(); } ?> <button id=’fire’>Fire Something</button> … Read more