• Hello, I have an issue with the functions get_post() and get_post_status() + Custom Post Types.
    I don’t have the same result when I call the list from a Page or an Archive Page.

    Issue WordPress 6.2.0
    – get_post( PostID )
    – get_post_status( PostID );

    Active Plugin:
    Advanced Custom Fields PRO Version 6.1.4

    In the a-z-listing.php page in my Child theme where I put this code

    echo 'Post Status > '.get_post_status(4701).'<br>'; 
    $getMyPost = get_post(4701);
    echo '<pre>';
    print_r($getMyPost);
    echo '</pre>';
    die;

    Code inside the archive-book.php

    // Query Get all Publish or Draft Posts
    $args = array(
    	'post_type' => 'book',
    	'orderby'   => 'title',
    	'order'     => 'ASC',
    	'post_status' => array('publish', 'draft'),
    );
    the_a_z_listing($args);
    

    When I call the A-Z List from a Page with the Shortcode [a-z-listing display=”posts” post-type=”book”] I get this result

    Post Status > draft
    
    WP_Post Object
    (
        [ID] => 4701
        [post_author] => 4
        [post_date] => 2023-04-13 15:20:01
        [post_date_gmt] => 0000-00-00 00:00:00
        [post_content] => 
        [post_title] => Book Status Test
        [post_excerpt] => 
        [post_status] => draft
        [comment_status] => closed
        [ping_status] => closed
        [post_password] => 
        [post_name] => 
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2023-04-13 15:20:01
        [post_modified_gmt] => 2023-04-13 13:20:01
        [post_content_filtered] => 
        [post_parent] => 0
        [guid] => https://www.mydomain.tld/?post_type=book&p=4701
        [menu_order] => 0
        [post_type] => book
        [post_mime_type] => 
        [comment_count] => 0
        [filter] => raw
    )

    When I call the archive page https://www.mydomain.tld/books/

    Post Status > publish
    WP_Post Object
    (
        [ID] => 4701
        [post_author] => 0
        [post_date] => 2023-04-13 15:20:01
        [post_date_gmt] => 0000-00-00 00:00:00
        [post_content] => 
        [post_title] => Book Status Test
        [post_excerpt] => 
        [post_status] => publish
        [comment_status] => open
        [ping_status] => open
        [post_password] => 
        [post_name] => 
        [to_ping] => 
        [pinged] => 
        [post_modified] => 0000-00-00 00:00:00
        [post_modified_gmt] => 0000-00-00 00:00:00
        [post_content_filtered] => 
        [post_parent] => 0
        [guid] => 
        [menu_order] => 0
        [post_type] => book
        [post_mime_type] => 
        [comment_count] => 0
        [filter] => raw
    )

    As you can see the result for the same post ID is not the same.

    From the Page > [post_status] => draf (correct answer)
    From the Archive > [post_status] => publish (wrong answer)

    I didn’t have this problem with WordPress 6.1.1

    I try to replace the_a_z_listing($args); by echo get_the_a_z_listing($args); or echo do_shortcode(‘[a-z-listing display=”posts” post-type=”book”]’); but I get the same result

    I do not understand why I get the wrong post status from the archive page?

    To solve the issue I had to downgrade WordPress from 6.2.0 to 6.1.1.

    • This topic was modified 1 year, 7 months ago by nexusfred.
Viewing 1 replies (of 1 total)
  • Thread Starter nexusfred

    (@nexusfred)

    I found a solution to get the correct Post Status.
    Apparently there is a problem with the WP_Query cache.

    In file : a-z-listing/src/Shortcode/PostsQuery.php

    Search for this code : (Line 62)

    $query = wp_parse_args(
    	$query, 
    	array(
    		'posts_per_page' => -1,
    		'nopaging'       => true,
    	)
    );

    and replace by :

    $query = wp_parse_args(
    	$query, 
    	array(
    		'posts_per_page' => -1,
    		'nopaging'       => true,
    		'cache_results'  => false
    	)
    );
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Types Status is wrong from Archive Page’ is closed to new replies.