Support » Plugin: Pods - Custom Content Types and Fields » Create a URL that links to the latest post in a category

  • Resolved Sarah H


    I have a CPT Pod “Document” with a category “Agendas” and I need to link to the single post page of the most recently posted Agenda on the front page of the website (icon in header on right).

    Can this be done with wp_query or find()? I am not that PHP savvy at all but I know how to add stuff to functions.php. I’ve seen lots of code snippets doing this for blog posts but only one relating to Pods which doesn’t tell me much:

    Even with the code snippets, I don’t know how to structure the URL parameters. I’ve experimented some but with no luck.

    Thanks in advance. Really enjoying PODs.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Paul Clark


    Video walkthrough

    		$posts = get_posts([
    			'post_type' => 'document',
    			'posts_per_page' => 1,
    			'orderby' => 'date',
    			'order' => 'DESC',
    			'tax_query' => [
    					'taxonomy' => 'document_category',
    					'field' => 'slug',
    					'terms' => 'agenda',
    			'<p><a href="%s">%s</a></p>',
    			get_permalink( $posts[0]->ID ),
    			get_the_title( $posts[0]->ID )
    		return ob_get_clean();
    Thread Starter Sarah H


    Thank you so much for the response Paul, the video walkthrough is very helpful!

    I’ve added this to the functions.php of my child theme and tested it by adding it to a few blog posts, but it seems to be returning the title and permalink of whatever post its in. For example:

    I’ve checked the code and it all matches, could there be something in my POD setup that’s creating this? Any thoughts? Much appreciated.


    Plugin Author Jory Hogeveen


    Hi @sarahrbcom

    I cannot access the links you’ve posted.
    The code Paul posted should work fine as it specifically targets the document post type, not other post types.

    Cheers, Jory

    Thread Starter Sarah H


    Hi Jory,

    Thanks for the response. Can you be more specific as to why you can’t access the links? Do you see an error message? The site is discouraging search engines but is otherwise entirely public. I can open the links in an incognito window, so logins and cookies are not an issue. It currently has no SSL, is that the issue for you?

    I understand how the code targets the document CPT, which is why I’m confused as to the results I’m seeing.

    Can you view this screenshot?
    I added class="shortcode-test" to the <p> tag to confirm that the shortcode was indeed printing that line, but the string it’s returning does not seem to be the correct permalink and title.

    Thread Starter Sarah H


    Came back to this with fresh eyes and picked it apart, and discovered that the code above uses agenda as the term when it’s actually agendas. With that change it works now! I’ve styled it as a button with generic text and it’s working great now. I’m sure this will be useful in the future for other projects, thanks again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.