Support Forum

Understanding Blog Linking

28 Answers

New Answer

CA Chris_Andrews
Chris_Andrews
Member

Well, I can add an sql statement under the SaveData part to give it a date: 

$sql = “UPDATE wp_sfposts SET post_date = “.$p->newpost[‘post_date’].” WHERE topic_id = “.$p->newpost[‘topicid’];

But I’m having trouble getting the $p->newpost[‘post_date’] value. I can hard code a date in there and it works, but I haven’t been able to figure out how to get that date in the code,

MP Mr Papa
Mr Papa
Member

sorry, not sure I follow…  seems you are saying that line of code works, but you cant get the $p->newpost[‘post_date’] value???  which seems to conflict with it working…  can you explain what code you have that is not working?

CA Chris_Andrews
Chris_Andrews
Member

Sorry I was unclear –  🙂 

If I do this: 

$sql = “UPDATE wp_sfposts SET post_date = “2016-06-26 11:02:4” WHERE topic_id = “.$p->newpost[‘topicid’];

I get that date into the database, so I know the sql works. 

I think I probably need to put this (or something else?): 

$p->newpost[‘post_date’] = $post->post_date; 

in before that, but I haven’t figured out what and where, so that the date that is on the original post is used.

MP Mr Papa
Mr Papa
Member

ah, I understand…  you cannot reference $post in that routine as it doesnt exist in the scope…  I had intended for you to put the code in the blog linking plugin itself AFTER the call to saveData…

looking at this a bit more, might need a bit more magic too…  

before:

$p->saveData();

add

add_action('sph_new_post', 'my_linking_code'); 
function my_linking_code($newpost) { 
global $spVars; 
$spVars['linkedpost'] = $newpost['postid']; 
}

and then after this:

$sql = "UPDATE ".SFTOPICS." SET blog_post_id = ".$post->ID." WHERE topic_id = ".$p->newpost['topicid'];
spdb_query($sql);

add:

$sql = "UPDATE ".SFPOSTS." SET post_date = ".$post->post_date." WHERE post_id = ".$sfVars['linkedpost'];
spdb_query($sql);

still untested… 🙁

CA Chris_Andrews
Chris_Andrews
Member

Alas, still getting today’s date. 

Sorry it took me a bit to get back to you on this. 

MP Mr Papa
Mr Papa
Member

well, there does seem to be an inconsistency in the code above…

in this code:

$sql = “UPDATE “.SFPOSTS.” SET post_date = “.$post->post_date.” WHERE post_id = “.$sfVars[‘linkedpost’];
spdb_query($sql);

the $sfVars array should be $spVars…

seems it should work… where exactly did you put the code I gave you?  try the code change first of course…

CA Chris_Andrews
Chris_Andrews
Member

Still seems like the $post->post_date isn’t available to the script. I can do this:

$sql = “UPDATE “.SFPOSTS.” SET post_date = ‘2017-02-20 10:06:45’ WHERE post_id = “.$spVars[‘linkedpost’];

and get that date in, but just get the current date if I do $post->post_date 

MP Mr Papa
Mr Papa
Member

have to admit, I have sort of lost the bubble here… need to reread – thinking we got sidetracked somewhere…

so what happens if you use $post->post_date??

its a standard wp post object, so should contain the date…

where exactly did you put this code?  can you paste it here?

do you know how to debug a bit?  where you are trying to do that, can you see what is in $post?  maybe add ashow($post); die(); right there and see what is shown…

CA Chris_Andrews
Chris_Andrews
Member

In sp-linking-blog.php I’ve added what’s in blue:

add_action(‘sph_new_post’, ‘my_linking_code’); add_action(‘sph_new_post’, ‘my_linking_code’); function my_linking_code($newpost) { global $spVars; $spVars[‘linkedpost’] = $newpost[‘postid’]; 

$p->saveData();
if (!$p->abort) { $editmode = ‘0’; if ((isset($_POST[‘sfedit’]) && $_POST[‘sfedit’] == true) || $links->syncedit == ‘1’) $editmode = ‘1’;
# and then update links table with forum AND topic sp_blog_links_control(‘save’, $post->ID, $forumid, $p->newpost[‘topicid’], $editmode);
# sync blog and forum tags sp_sync_blog_tags($post->ID, $forumid, $topicid);
# Add the blog post id into the topic record $sql = “UPDATE “.SFTOPICS.” SET blog_post_id = “.$post->ID.” WHERE topic_id = “.$p->newpost[‘topicid’]; spdb_query($sql);

$sql = “UPDATE “.SFPOSTS.” SET post_date = “.$post->post_date.” WHERE post_id = “.$spVars[‘linkedpost’];spdb_query($sql);

} else {

 

I know, it seems like .$post->post_date. should be in the scope. I just get today’s date (at the time I update it) instead of the original published date though. 

If I add show($post); die();  after that sql statement and then do an ‘update’ in the wp page editor, it just crashes the page. I don’t get a string.

MP Mr Papa
Mr Papa
Member

did you enter ‘show’ or ‘ashow’???  might seem odd, but it needs to be ‘ashow’ which is not what you typed…

sorry, havent had a chance yet to actually test this myself…  anniversary weekend…  and memorial day holiday…  but will…

CA Chris_Andrews
Chris_Andrews
Member

Oh, ok, I looked up “ashow” related to php and wp and only got hits on “show”, so I thought that was what you meant. 

Ok, I get this (below), which shows that the post_date is there…. then why am I not getting it into the database? If I can hardcode a date in and it works, I should be able to use $post->post_date … hmmm, something isn’t making sense, relooking at and retesting everything. 

 

stdClass Object ( [ID] => 45449 [post_author] => 1028 [post_date] => 2016-03-10 22:01:01 [post_date_gmt] => 2016-03-11 03:01:01 [post_content] => //article removed for brevity [post_title] => //title removed [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => //removed [to_ping] => [pinged] => [post_modified] => 2017-05-29 10:59:03 [post_modified_gmt] => 2017-05-29 14:59:03 [post_content_filtered] => [post_parent] => 0 [guid] => //removed [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 )
MP Mr Papa
Mr Papa
Member

sorry, I just didnt look hard enough and missed the obvious… php syntax error there (which is why I asked about error log)…  please try this:

$sql = "UPDATE ".SFPOSTS." SET post_date = '".$post->post_date."' WHERE post_id = ".$spVars['linkedpost'];
spdb_query($sql);

be sure to use raw copy on the code…  just need single quotes around the date…

CA Chris_Andrews
Chris_Andrews
Member

Success 🙂 

What kills me is I would have caught that a decade ago, but since I’m using wp on all my sites now and not really doing any coding, I’ve forgotten stuff and don’t have an eye for it anymore. Don’t use it and I lose it.

Thanks for helping and sticking with me through this. Next I’ll try to figure out the actual hard part, see if I can figure out a way to transfer comments over. That may be beyond what I can do, but I’ll look into it at least,

I have been able to hack in in-post adsense ads and some adsense sharing code (the author of the original post gets a 70% adshare on their content) and that’s looking good and working well. I’ll show it all off when I get done messing with it 🙂 

Chris