{"id":6178698,"date":"2015-05-29T07:54:21","date_gmt":"2015-05-29T07:54:21","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/get-events-from-database\/"},"modified":"2016-08-24T16:45:15","modified_gmt":"2016-08-24T16:45:15","slug":"get-events-from-database","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/get-events-from-database\/","title":{"rendered":"Get events from database"},"content":{"rendered":"<p>Hello Developer,<br \/>\nI have two running wp site in a same database and in one of them I&#8217;ve setup your event plugin.<\/p>\n<p>I&#8217;ve added the code below to get the same events on other site pulling out directly from the database, so I add events just one time.<\/p>\n<p>I would like to ask you how can i add the start date on the event and how i have to improve the sql code.<\/p>\n<p>When I&#8217;ve added the StartDate value from the table eo_events i get duplicated results.<br \/>\nFor example, every dates is present, it&#8217;s attacched for every single event.<\/p>\n<p>I know it&#8217;s a bit tricky but I hope you can help me.<br \/>\nThanks a lot<\/p>\n<pre><code>$mydb = new wpdb(&#039;user&#039;,&#039;pass&#039;,&#039;database&#039;,&#039;host&#039;);\n$events = $mydb-&gt;get_results(&quot;SELECT post_title, post_name, StartDate FROM wp_posts, eo_events WHERE post_type = &#039;event&#039;&quot;);\n\nforeach ($events as $obj) : ?&gt;\n&lt;div id=&quot;&lt;?php echo $obj-&gt;post_id; ?&gt;&quot; class=&quot;fusion-one-third one_third fusion-layout-column fusion-column spacing-yes post&quot;&gt;\n &lt;div class=&quot;fusion-date-and-formats&quot;&gt;\n     &lt;div class=&quot;fusion-date-box updated&quot;&gt;\n        &lt;span class=&quot;fusion-date&quot;&gt;\n            &lt;?php echo date(&#039;j&#039;, strtotime($obj-&gt;StartDate)); ?&gt;&lt;\/span&gt;\n        &lt;span class=&quot;fusion-month-year&quot;&gt;\n            &lt;?php\n    setlocale(LC_ALL, &#039;it_IT&#039;);\n    echo strftime(&#039;%b %Y&#039;, strtotime($obj-&gt;StartDate));\n            ?&gt;&lt;\/span&gt;\n    &lt;\/div&gt;\n &lt;div class=&quot;fusion-format-box&quot;&gt;&lt;i class=&quot;fa fa-calendar&quot;&gt;&lt;\/i&gt;&lt;\/div&gt;\n&lt;\/div&gt;\n &lt;div class=&quot;fusion-post-content post-content&quot;&gt;\n     &lt;h2 class=&quot;entry-title&quot;&gt;\n        &lt;a target=&quot;_blank&quot; href=&quot;&lt;?php echo $obj-&gt;post_name; ?&gt;&quot;&gt;&lt;?php echo $obj-&gt;post_title; ?&gt;&lt;\/a&gt;\n     &lt;\/h2&gt;\n &lt;\/div&gt;\n&lt;\/div&gt;\n\n&lt;? endforeach; ?&gt;<\/code><\/pre>\n<p>screenshot:<br \/>\ncurrently I&#8217;ve just six events, look how many i get \ud83d\ude41<br \/>\n[IMG]http:\/\/i57.tinypic.com\/209fz8g.png[\/IMG]<br \/>\n<a href=\"http:\/\/i57.tinypic.com\/209fz8g.png\">screenshot<\/a><\/p>\n<p>https:\/\/wordpress.org\/plugins\/event-organiser\/<\/p>\n","protected":false},"template":"","class_list":["post-6178698","topic","type-topic","status-closed","hentry","topic-tag-database","topic-tag-events","topic-tag-mysql","topic-tag-php","topic-tag-query"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6178698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6178698\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6178698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}