davidg

Create new post using existing post as template

Recommended Posts

I would like to have an automated post made to a topic after pinning it. The content of this new post i'd like to have come from another post (saved in a templates forum) that is editable by members not having access to the ACP. I know its possible, i've seen it done elsewhere using this plugin, but I am not sure how to set it up.


Thanks!

Share this post


Link to post
Share on other sites

You cant do that with stock rules. You would need to use custom php code for the argument to the conent field of your "create topic comment" action. In that custom php code, you need to load the "template" topic object, retrieve its content, and return it as your argument value for the content of your posted comment.

 

Share this post


Link to post
Share on other sites
1 hour ago, Kevin Carwile said:

You cant do that with stock rules. You would need to use custom php code for the argument to the conent field of your "create topic comment" action. In that custom php code, you need to load the "template" topic object, retrieve its content, and return it as your argument value for the content of your posted comment.

 

Thanks, would you happen to know what that php code might look like?

Share this post


Link to post
Share on other sites

Incase someone wants to do this, here is the PHP code you need:

// This works by pulling up the content of the first post of the topic you designate by ID number.
// To find a topic's ID, look at the topic's URL, it's a five or six digit number


// Replace the number below with your topic number

$topic_number = "90";

$myvar = "";


// LINKS TO DATABSE
$link = new mysqli('DB_ADDRESS', 'DB_USER', 'DB_PASS') or die('Could not connect: ' . $link->error);
$link->select_db('DB_NAME') or die('Could not select database');

// PULLS TOPIC TO FIND POST ID
$show_results = mysqli_query($link,"SELECT * FROM forums_topics WHERE tid='$topic_number'")  or die ("Couldn't find the topic with that number");
while($row = mysqli_fetch_array($show_results)){
    $topic_id = $row['topic_firstpost'];
    $myvar = $topic_id;
}

// PULLS POST CONTENT FROM POST ID
$show_results2 = mysqli_query($link,"SELECT * FROM forums_posts WHERE pid='$topic_id'")  or die ("Couldn't find the PID part");
while($row = mysqli_fetch_array($show_results2)){
    $myvar =  $row['post'];
}

// REMOVE nbsp TAG AND REPLACES WITH HTML FRIENDLY VERSION

// This is required due to a bug with the automation return
$output = str_replace("\xA0", "&#160", $myvar);

return "$output";
Edited by davidg
  • Like 1

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.