Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress, storing article publishing date and time in variable
    primarykey
    data
    text
    <p>First of all, let me explain, what I want to do. I have a unique table for every user where they can see their posts, edit, delete them in front end. But when they create an article, it's status being "Pending", because only I, as administrator, can give the status "Published" to it. What I want to do is to show for users the date when their post was created or last modified by them, and then, the date when it was published.</p> <p>How to show publishing date I know. Because <code>get_the_date('Y-m-d');</code> works ok with this, because it shows date when post was modified at all by any user. But I need to store somewhere the date then it was modified last by users.</p> <p>What I managed to do is something like this:</p> <pre><code>&lt;?php $id = get_the_ID(); ?&gt; &lt;?php $the_last_time="the_time_". $id; ?&gt; &lt;?php $the_last_date="the_date_". $id; ?&gt; &lt;?php if ( in_array( $post-&gt;post_status, array('draft', 'future', 'pending') ) ) { ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'wpuf' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;p&gt;&lt;?php echo get_the_time('G:i'); ?&gt;&lt;/p&gt; &lt;p&gt;&lt;?php echo get_the_date('Y-m-d'); ?&gt;&lt;/p&gt; &lt;?php $$the_last_time=get_the_time('G:i'); ?&gt; &lt;?php $$the_last_date=get_the_date('Y-m-d'); ?&gt; &lt;?php setcookie("$the_last_time", $$the_last_time, time()+2592000); ?&gt; &lt;?php setcookie("$the_last_date", $$the_last_date, time()+2592000); ?&gt; &lt;?php } else { ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'wpuf' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; &lt;p&gt;&lt;?php echo htmlspecialchars($_COOKIE["$the_last_time"]) ?&gt;&lt;/p&gt; &lt;p&gt;&lt;?php echo htmlspecialchars($_COOKIE["$the_last_date"]) ?&gt;&lt;/p&gt; &lt;?php } ?&gt; &lt;?php wpuf_show_post_status( $post-&gt;post_status ) ?&gt; &lt;p&gt;&lt;?php echo get_the_time('G:i'); ?&gt;&lt;/p&gt; &lt;p&gt;&lt;?php echo get_the_date('Y-m-d'); ?&gt;&lt;/p&gt; </code></pre> <p>As you can see I'm using cookies to store these variables. But the problem is, that it's storing variable information only in one users computer, and what I need is that every user loged in from any computer could see these dates.</p> <p>Thanks in advance for any leads that could help me. ;)</p> <p>----------EDIT----------</p> <p>I tried to create a .php file and there store these variables. Then when I need thenm I could include that file, but I'm doing something wrong because it don't work.</p> <pre><code>//Creating variables &lt;?php $id = get_the_ID(); ?&gt; &lt;?php $the_last_time="the_time_". $id; ?&gt; &lt;?php $the_last_date="the_date_". $id; ?&gt; &lt;?php $the_last_time_file="the_time_file_". $id; ?&gt; &lt;?php $the_last_date_file="the_date_file_". $id; ?&gt; //Every time after user modification &lt;?php $$the_last_time=get_the_time('G:i'); ?&gt; &lt;?php $$the_last_date=get_the_date('Y-m-d'); ?&gt; &lt;?php $$the_last_date_file=var_export($$the_last_date, true);?&gt; &lt;?php $$the_last_date_file="&lt;?php\n\n\$$the_last_date_file = $$the_last_date;\n\n?&gt;";?&gt; &lt;?php file_put_contents('/cookies/time-date-variables.php', $$the_last_date_file);?&gt; //And when I publish that post it should show echo variable &lt;?php include '/cookies/time-date-variables.php'; ?&gt; &lt;?php echo $$the_last_date_file; ?&gt; </code></pre> <p>What I'm doing wrong? Any leads?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload