my simple shortcode retrieves a list of articles as text files from a folder. These articles are in html format (with h2, p ...). I use a plugin which creates the pages I need on the fly in which I insert my shortcode. The shortcode works well and the html rendering is ok in the articles, BUT:
the problem: the shortcode updates with each page load and makes different content each time.
What do you think is the method to "fix" this because I can't? I tried to write the content of the shortcode in the database in post_content? And remove the shortcode from the articles to be able to edit them later in wordpress. I have made several attempts but nothing, thank you for your help
function my_shortcode(){
$path_to_myplugin = WP_PLUGIN_DIR . '/my_plugin_name/';
$thema_folder = "themafolder";
$passage = fopen($path_to_myplugin.'nbr-init.txt', 'r+');//Stock passage, Start to 0
$number_passage = fgets($passage); // Read the first line
$number_passage += 1; // +1
fseek($passage, 0); // cursor at start of file
fputs($passage, $number_passage); // Rewrite the new number
fclose($passage);
@$file_name = $thema_folder."/"."art-".$thema_folder."-".$number_passage.".txt";
$content = file_get_contents($path_to_myplugin.$file_name);// Ok it works
// I try to write the shortcode to the post_content but not working:
global $wpdb;
$wpdb->insert{
$args = array(
'post_content' => $content
)
};
$content = wp_insert_post( $args );
return $content;
}
add_shortcode ('myshortcode', 'my_shortcode');