Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Convert to Slug

1
2
3
function convertToSlug(text) {
	return text.replace(/ +/g, '-').toLowerCase();
}
https://snipt.net/embed/d2c8e388d771b7652e62f77c3245951a/
https://snipt.net/raw/d2c8e388d771b7652e62f77c3245951a/
d2c8e388d771b7652e62f77c3245951a
js
JavaScript
3
2016-12-06T17:48:22
True
False
False
/api/public/snipt/55436/
convert-to-slug
<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="kd">function</span> <span class="nx">convertToSlug</span><span class="p">(</span><span class="nx">text</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="nx">text</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/ +/g</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">).</span><span class="nx">toLowerCase</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
"text convert", slug

PHP

Get post ID from Slug in WordPress

<?php $ID = url_to_postid(slug); ?>
https://snipt.net/embed/320dacfcc774b008d9430231f975308b/
https://snipt.net/raw/320dacfcc774b008d9430231f975308b/
320dacfcc774b008d9430231f975308b
php
PHP
1
2016-12-06T11:32:00
True
False
False
Aug 27, 2012 at 04:14 PM
/api/public/snipt/46352/
get-post-id-from-slug-in-wordpress
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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 class="nv">$ID</span> <span class="o">=</span> <span class="nx">url_to_postid</span><span class="p">(</span><span class="nx">slug</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
id, slug, wordpress

PHP

Return (echo) post parent's slug (name) in WordPress

1
2
3
4
5
6
<?php // Return parent slug
    $parent_post_id = $post->post_parent;
    $parent_post = get_post($parent_post_id); 
    $parent_post_title = $parent_post->post_title; 
    echo $parent_post_title; 
?>
https://snipt.net/embed/9abef16d5601d7220868ca0642011cc4/
https://snipt.net/raw/9abef16d5601d7220868ca0642011cc4/
9abef16d5601d7220868ca0642011cc4
php
PHP
6
2016-12-06T11:32:35
True
False
False
/api/public/snipt/42087/
return-echo-post-parents-slug-name-in-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></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 class="c1">// Return parent slug</span> </span><span id="L-2"><a name="L-2"></a> <span class="nv">$parent_post_id</span> <span class="o">=</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">post_parent</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$parent_post</span> <span class="o">=</span> <span class="nx">get_post</span><span class="p">(</span><span class="nv">$parent_post_id</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$parent_post_title</span> <span class="o">=</span> <span class="nv">$parent_post</span><span class="o">-&gt;</span><span class="na">post_title</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">echo</span> <span class="nv">$parent_post_title</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
post_parent, slug, wordpress
Copyrighted, illegal, or inappropriate content? Email [email protected].