snipt

Ctrl+h for KB shortcuts

PHP

Related post excluding current post

1
2
3
4
5
6
7
<?php
$currentID = get_the_ID();
$my_query = new WP_Query( array('cat' => '1', 'showposts' => '5', 'post__not_in' => array($currentID)));
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h2>
<?php the_content(); ?>
<?php endwhile; ?>
https://snipt.net/embed/2253bb0bc247ecf3bf2c5050102d3289/
https://snipt.net/raw/2253bb0bc247ecf3bf2c5050102d3289/
2253bb0bc247ecf3bf2c5050102d3289
php
PHP
7
2016-09-28T15:48:50
True
False
False
Feb 10, 2016 at 07:55 PM
/api/public/snipt/144098/
related-post-excluding-current-post
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$currentID</span> <span class="o">=</span> <span class="nx">get_the_ID</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$my_query</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WP_Query</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;cat&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="s1">&#39;showposts&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;5&#39;</span><span class="p">,</span> <span class="s1">&#39;post__not_in&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="nv">$currentID</span><span class="p">)));</span> </span><span id="L-4"><a name="L-4"></a><span class="k">while</span> <span class="p">(</span> <span class="nv">$my_query</span><span class="o">-&gt;</span><span class="na">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="nv">$my_query</span><span class="o">-&gt;</span><span class="na">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-5"><a name="L-5"></a><span class="x">&lt;h2&gt;&lt;a href=&quot;</span><span class="cp">&lt;?php</span> <span class="nx">the_permalink</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x">&quot;&gt;</span><span class="cp">&lt;?php</span> <span class="nx">the_title</span><span class="p">()</span> <span class="cp">?&gt;</span><span class="x">&lt;/a&gt;&lt;/h2&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">&lt;?php</span> <span class="nx">the_content</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-7"><a name="L-7"></a><span class="cp">&lt;?php</span> <span class="k">endwhile</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
query, related

PHP

Cakephp last query log

$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);
https://snipt.net/embed/00dba0417ae40571acd7d7c4c527397a/
https://snipt.net/raw/00dba0417ae40571acd7d7c4c527397a/
00dba0417ae40571acd7d7c4c527397a
php
PHP
2
2016-09-21T11:50:27
True
False
False
/api/public/snipt/96592/
cakephp-last-query-log
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">$log = $this-&gt;Model-&gt;getDataSource()-&gt;getLog(false, false);</span> </span><span id="L-2"><a name="L-2"></a><span class="x">debug($log);</span> </span></pre></div> </td></tr></table>
Cakephp, last_query, query, query_log
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.