Site icon Hip-Hop Website Design and Development

menu merchandise to show the latest put up

I spent many of the day reviewing previous questions and solutions and haven’t discovered something that addresses what I’m attempting to do. Possibly I did not phrase my search accurately.

Let’s imagine I’ve a class of posts for paperwork that mirror present committee members. I can create a WP menu merchandise for a particular put up with WordPress Nonetheless, customers can submit new posts utilizing the USP Professional plugin. Now the menu merchandise must level to probably the most just lately up to date put up. I need to keep away from having to replace the menu each time a brand new put up is added.

I created a brief code operate in my features.php file to get the latest put up for a class (brief code argument). Once I try and redirect to the permalink for that put up, I get a clean web page.

    //[latestpost]
operate get_latest_post( $atts) { extract( shortcode_atts( array( 'cat' => '', ), $atts, 'latestpost' ) ); $args = array( 'posts_per_page' => 1, // we'd like solely the newest put up, so get that put up $ 'cat' => $cat, // Use the class id, can even exchange with category_nam$ //'category_name' => 'SLUG OF FOO CATEGORY, ); $q = new WP_Query( $args); if ( $q->have_posts() ) { whereas ( $q->have_posts() ) { $q->the_post(); //Your template tags and markup like: //the_title(); $hyperlink=get_permalink($put up); // echo $hyperlink; // echo $cat; if ( wp_redirect( $hyperlink) ) { exit; } } wp_reset_postdata(); } } add_shortcode('latestpost','get_latest_post')`  

I put in a few echo statements to verify that the operate was getting the proper class ($cat) and permalink. They seem on the web page however the web page will not be redirected.

Operating WordPress 5.1 with a twenty seventeen little one theme.

Thanks on your assist.