Display recent posts from portfolio

You can get latest post from any post type with the simple query <?php // Arguments $args = array( ‘post_type’ => ‘portfolio’, ); // The Query $the_query = new WP_Query( $args ); // The Loop if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } … Read more

Call current post URL in ajax

you can retrieve the permalink of the current post in JavaScript with wp_localize_script. juste try this code after the call of wp_enqueue_script wp_localize_script( “script_id” , “object” , [ “permalink” => get_post_permalink($post), ] ); and then you can read the permalink in JavaScript in object[“permalink”]

Display the 2nd category name of a custom post type without error if its null?

Inside of your loop you can get the terms via wp_get_post_terms function. Then, check if two or more terms exist. If they do, then use the function array_slice to extract the second term that appears in the array: $term_list = wp_get_post_terms( $post->ID, ‘YOUR_TAXONOMY’, array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘fields’ => ‘all’) ); $display_term = … Read more

how to execute some code after a post is published in WordPress [duplicate]

You’re looking for the save_post action. This allows you to add a function when a post is saved (updated). You can hook into it like this: function your_save_post_function( $post_id ) { } add_action( ‘save_post’, ‘your_save_post_function’ ); Remember to not change WordPress Core files, as these will be overwritten when WordPress is updated. You can put … Read more

HTML Form Submit to table in same page

Couple of things with this. Your action attribute is empty. That’s the attribute that tells the browser where to send the posted form data. Should be a field or if you’re using AJAX, I always put # in there and let the javascript do it’s thing. Not sure about the cf_name attribute in your input … Read more

Post Form Results to Table in Same page

You can have an ajax action that sent the data to the backend populate the table and return the success or the errors back. You can use this actions add_action(‘wp_ajax_*’, ‘custom_table_insert’); add_action(‘wp_ajax_nopriv_*’, ‘custom_table_insert’); // anonymous users This will give you more control and ultimately a far better user experience. // Ajax Request template jQuery.ajax({ url … Read more