Post becomes 404 if author is changed manually

This topic contains 6 replies, has 3 voices, and was last updated by  Stiofan O’Connor 9 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #59574

    Y A
    Expired Member
    Post count: 156

    This might be a tough one.

    My goal is to have all added listings automatically belong to the Administrator. So, I have something like this:

    UPDATE $wpdb->posts SET post_author=1 WHERE ID = %d

    I have also tried directly changing the

    post_author

    in PHPmyadmin, and using the

    wp_update_post

    function.

    In all cases, when the author is changed (to administrator), the Listing page becomes 404 and does not appear (whether draft or publish). If I manually change back the

    post_author

    to its original value, the listing page suddenly appears.

    Any ideas on why this is happening ?

    Note that this does not happen on normal WordPress instances (not running GD)

    #59575

    Paolo
    Site Admin
    Post count: 31206

    You need to change the author ID in geodir table too:

    wp_geodir_gd_place_details

    Thanks

    #59576

    Y A
    Expired Member
    Post count: 156

    I thought of that, but I did not find an author ID field in the wp_geodir_gd_place_detail table

    #59583

    Paolo
    Site Admin
    Post count: 31206

    Ops, I’m sorry I said something wrong. The author id is indeed only present in the wp_posts table.

    I’ve asked to Stiofan to take this on and see what’s happening.

    Please provide URL and credentials of both website and phpmyadmin and he’ll let you know asap.

    Thanks

    #59589

    Y A
    Expired Member
    Post count: 156

    Alright, thanks.

    Unfortunately, my test website is on localhost (and you can imagine why I wouldn’t want to put it on my live website).

    Stiofan, please let me know if you can’t get this to replicate on your test website and I’ll create another instance of my website online.

    #59637

    Y A
    Expired Member
    Post count: 156

    Update!
    Turns out that if I also manually publish the post, it works fine. Here’s the final code in case anyone cares:

    
    
    function syr_replace_author( $last_post_id )  
    {
    	global $wpdb;
    	$this_post = $wpdb->get_row(
    		$wpdb->prepare("SELECT * FROM wp_geodir_gd_place_detail WHERE post_id = %d", $last_post_id)
    		);
    	
    	if ($this_post->post_status == 'draft' && !$this_post->claimed && $this_post->package_id =='1') {
    
    		$my_post = array();
    		$my_post['ID'] = $last_post_id;
    		$my_post['post_author'] = 1 ; //This is the ID number of whatever author you want to assign
    
    		// Update author into the database
    		wp_update_post($my_post);
    
    		// Publish posts when added
    		wp_publish_post ($last_post_id);
    		geodir_change_post_status($last_post_id, 'publish');
    		
    	}
    }
    add_action( 'geodir_after_save_listing', 'syr_replace_author');
    #59665

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    That was the first thing i thought, maybe u changed the ID to another user and the post was not published, this can cause a 404. Glad you got it resolved.

    Thanks,

    Stiofan

Viewing 7 posts - 1 through 7 (of 7 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount