• Is it possible to retrieve the last 3 custom post that have been generated by a plugin?
    To make it clear:
    I am using a plugin that show galleries dynamically, so every time the user click on a link, the gallery link is generated according to albumname and galleryname.
    I was able to create a script that retrieve the galleryname from the mysql database, but I cannot associate it with the albumname, so I cannot show a link of the lasts added gallery.
    I was wondering if there is a function that retrieves the lasts 3 posts (custom posts) generated by this plugin and show a link for each of them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here is how you can do it. But make sure to change the post_type slug as per your need. In this example I have used gallery_cpt

    1. Setup a custom query
    
    $args = array(
        'post_type'      => 'gallery_cpt',
        'posts_per_page' => 3,       
        'orderby'        => 'date',          
        'order'          => 'DESC' 
    );
    $the_query = new WP_Query($args);
    

    2. Loop through the above query and display the results accordingly

    if ($the_query->have_posts()) :
        while ($the_query->have_posts()) : $the_query->the_post();
            echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
        endwhile;
        wp_reset_postdata();
    else :
        echo '<p>No posts found.</p>';
    endif;
    Thread Starter mobius01001

    (@mobius01001)

    thanks for your quick reply!
    I am able to gets the array with the “post_type”, but I am pretty sure that this trick does not give me the link, cause everytime a gallery is requested by user, the request also elaborate the album, type of visualization (thumbnail, compact, etc), numebr of images per page, everytime for each gallery.
    Is there a way that simply scrape all the last link generated by that specific plugin?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get Link of last added custom post’ is closed to new replies.