• Resolved deb

    (@debendra)


    https://www.ads-software.com/support/topic/the-post-url-will-give-404-error
    My problem is same like in the given link, I tried to use pre_get_posts to exclude archive posts only, but I got opposite result. My code is:

    add_filter( 'aps_status_arg_public', '__return_true' );
    add_filter( 'aps_status_arg_private', '__return_false' );
    add_filter( 'aps_status_arg_exclude_from_search', '__return_false' );

    // Load our function when hook is set

    add_action( 'pre_get_posts', 'rc_modify_query_exclude_category' );
    
    function rc_modify_query_exclude_category( $query ) {
    	// Check if on frontend and main query is modified
        if ( ! is_admin() && $query->is_main_query() && ! $query->get( 'post_status' ) ) {
            $query->set( 'post_status', 'archive' );
        } // end if
    }

    with this code, i got list of archived post only but I need to remove archived post, i am not good in php, can you or anyone help please ???

    https://www.ads-software.com/plugins/archived-post-status/

Viewing 1 replies (of 1 total)
  • Thread Starter deb

    (@debendra)

    I have crossed my sillyness here, I think I have done very very silly.

    add_filter( 'aps_status_arg_public', '__return_true' );
    add_filter( 'aps_status_arg_private', '__return_false' );
    add_filter( 'aps_status_arg_exclude_from_search', '__return_false' );
    
    function textdomain_exclude_category( $query ) {
        if ( ! $query->is_admin() && $query->is_main_query() && $query->is_archive() ) {
            $query->set( 'post_status', 'publish' );
        }
    }
    add_action( 'pre_get_posts', 'textdomain_exclude_category' );

    Just change post_status archive to publish and it works !!!!

Viewing 1 replies (of 1 total)
  • The topic ‘404 error’ is closed to new replies.