snipt

Ctrl+h for KB shortcuts

PHP

Sorting posts by custom field in wordpress

1
2
3
4
5
6
7
8
<?php
//the meta gets the name of the custom field(meta_key) and some other values
// the_meta();
//sort_query_posts_by('title', 'asc'); 
$meta_key = 'wpcf-broj-zvjezdica2';
//query_posts('meta_key=' . $meta_key . '&orderby=meta_value&order=DSC');
query_posts('meta_key=' . $meta_key . '&meta_value=3&order=DSC');
?>
https://snipt.net/embed/d0df3756739c421ea512723e9323a938/
/raw/d0df3756739c421ea512723e9323a938/
d0df3756739c421ea512723e9323a938
php
PHP
8
2019-08-25T17:48:22
True
False
False
/api/public/snipt/41776/
sortiranje-postova-po-custom-fieldu-wordpress
<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> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><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="c1">//the meta gets the name of the custom field(meta_key) and some other values</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">// the_meta();</span> </span><span id="L-4"><a name="L-4"></a><span class="c1">//sort_query_posts_by(&#39;title&#39;, &#39;asc&#39;); </span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$meta_key</span> <span class="o">=</span> <span class="s1">&#39;wpcf-broj-zvjezdica2&#39;</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="c1">//query_posts(&#39;meta_key=&#39; . $meta_key . &#39;&amp;orderby=meta_value&amp;order=DSC&#39;);</span> </span><span id="L-7"><a name="L-7"></a><span class="nx">query_posts</span><span class="p">(</span><span class="s1">&#39;meta_key=&#39;</span> <span class="o">.</span> <span class="nv">$meta_key</span> <span class="o">.</span> <span class="s1">&#39;&amp;meta_value=3&amp;order=DSC&#39;</span><span class="p">);</span> </span><span id="L-8"><a name="L-8"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
Wordpress

SQL

Wordpress DB Migrate

1
2
3
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl'; 
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com'); 
https://snipt.net/embed/f2bdc413ebd09705d8da8e800c02eb04/
/raw/f2bdc413ebd09705d8da8e800c02eb04/
f2bdc413ebd09705d8da8e800c02eb04
sql
SQL
3
2019-08-24T08:02:10
True
False
False
/api/public/snipt/40777/
wordpress-db-migrate-1
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">UPDATE</span> <span class="n">wp_options</span> <span class="k">SET</span> <span class="n">option_value</span> <span class="o">=</span> <span class="k">replace</span><span class="p">(</span><span class="n">option_value</span><span class="p">,</span> <span class="s1">&#39;http://www.oldsite.com&#39;</span><span class="p">,</span> <span class="s1">&#39;http://www.newsite.com&#39;</span><span class="p">)</span> <span class="k">WHERE</span> <span class="n">option_name</span> <span class="o">=</span> <span class="s1">&#39;home&#39;</span> <span class="k">OR</span> <span class="n">option_name</span> <span class="o">=</span> <span class="s1">&#39;siteurl&#39;</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a><span class="k">UPDATE</span> <span class="n">wp_posts</span> <span class="k">SET</span> <span class="n">guid</span> <span class="o">=</span> <span class="k">replace</span><span class="p">(</span><span class="n">guid</span><span class="p">,</span> <span class="s1">&#39;http://www.oldsite.com&#39;</span><span class="p">,</span><span class="s1">&#39;http://www.newsite.com&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="k">UPDATE</span> <span class="n">wp_posts</span> <span class="k">SET</span> <span class="n">post_content</span> <span class="o">=</span> <span class="k">replace</span><span class="p">(</span><span class="n">post_content</span><span class="p">,</span> <span class="s1">&#39;http://www.oldsite.com&#39;</span><span class="p">,</span> <span class="s1">&#39;http://www.newsite.com&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
Wordpress, database, migration