<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Custom post wordpress - Hi You, I am Tade</title>
	<atom:link href="https://hoangthuc.com/category/wordpress/wordpress-nang-cao/custom-post-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://hoangthuc.com/category/wordpress/wordpress-nang-cao/custom-post-wordpress/</link>
	<description></description>
	<lastBuildDate>Wed, 15 Mar 2023 03:49:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://hoangthuc.com/wp-content/uploads/2024/02/logoTH-2-150x150.png</url>
	<title>Custom post wordpress - Hi You, I am Tade</title>
	<link>https://hoangthuc.com/category/wordpress/wordpress-nang-cao/custom-post-wordpress/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Thêm bộ lọc taxonomy trong admin custom post type</title>
		<link>https://hoangthuc.com/bo-loc-taxonomy-trong-admin-custom-post/</link>
					<comments>https://hoangthuc.com/bo-loc-taxonomy-trong-admin-custom-post/#comments</comments>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Sun, 28 May 2017 12:47:52 +0000</pubDate>
				<category><![CDATA[Custom post wordpress]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress nâng cao]]></category>
		<category><![CDATA[Taxonomy filter admin custom post]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=493</guid>

					<description><![CDATA[<p>Đây là đoạn code nhỏ dùng để tạo bộ lọc custom taxonomy trong admin custom post type CMS wordpress. Để có thể dễ dàng quản lý bài viết trên site. Giao diện như bên dưới. Vẫn như củ các bạn copy code và đặt vào file functions.php thôi nhưng chú ý 1 số thông số như sau: [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/bo-loc-taxonomy-trong-admin-custom-post/">Thêm bộ lọc taxonomy trong admin custom post type</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Đây là đoạn code nhỏ dùng để tạo bộ lọc <strong>custom taxonomy</strong> trong <strong>admin custom post type</strong> CMS wordpress. Để có thể dễ dàng quản lý bài viết trên site. Giao diện như bên dưới.</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-494 size-full" src="https://hoangthuc.com/wp-content/uploads/2017/05/Untitled.png" alt="" width="1335" height="645" srcset="https://hoangthuc.com/wp-content/uploads/2017/05/Untitled.png 1335w, https://hoangthuc.com/wp-content/uploads/2017/05/Untitled-300x145.png 300w, https://hoangthuc.com/wp-content/uploads/2017/05/Untitled-900x435.png 900w" sizes="(max-width: 1335px) 100vw, 1335px" /></p>
<p>Vẫn như củ các bạn copy code và đặt vào file functions.php thôi nhưng chú ý 1 số thông số như sau:</p>
<p>1.Hook : Mình sử dung 2 hook là <strong>restrict_manage_posts</strong> và <strong>parse_query</strong>.</p>
<p><strong>restrict_manage_posts</strong> để lấy data taxonomy và hiển thị ra dạng dropdown taxonomy</p>
<p><strong>parse_query</strong> cải tạo lại bộ lọc để nó có thể filter thêm cái taxonomy mình mới thêm.</p>
<p>2.Biến: Bạn thay biến post_type và taxonomy thành của mình để sử dụng nhé.</p>
<p>3.Code đây</p>
<pre class="brush: php; title: ; notranslate">

add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
 global $typenow;
 $post_type = 'project'; // change to your post type
 $taxonomy = 'kind'; // change to your taxonomy
 if ($typenow == $post_type) {
 $selected = isset($_GET&#x5B;$taxonomy]) ? $_GET&#x5B;$taxonomy] : '';
 $info_taxonomy = get_taxonomy($taxonomy);
 wp_dropdown_categories(array(
 'show_option_all' =&gt; __(&quot;Lọc {$info_taxonomy-&gt;label}&quot;),
 'taxonomy' =&gt; $taxonomy,
 'name' =&gt; $taxonomy,
 'orderby' =&gt; 'name',
 'selected' =&gt; $selected,
 'show_count' =&gt; true,
 'hide_empty' =&gt; true,
 ));
 };
}
/**
 * Filter posts by taxonomy in admin
 * @author Hoang Thuc
 * @link https://hoangthuc.com/bo-loc-taxonomy-trong-admin-custom-post
 */
add_filter('parse_query', 'tsm_convert_id_to_term_in_query');
function tsm_convert_id_to_term_in_query($query) {
 global $pagenow;
 $post_type = 'project'; // change to your post type
 $taxonomy = 'kind'; // change to your taxonomy
 $q_vars = &amp;$query-&gt;query_vars;
 if ( $pagenow == 'edit.php' &amp;&amp; isset($q_vars&#x5B;'post_type']) &amp;&amp; $q_vars&#x5B;'post_type'] == $post_type &amp;&amp; isset($q_vars&#x5B;$taxonomy]) &amp;&amp; is_numeric($q_vars&#x5B;$taxonomy]) &amp;&amp; $q_vars&#x5B;$taxonomy] != 0 ) {
 $term = get_term_by('id', $q_vars&#x5B;$taxonomy], $taxonomy);
 $q_vars&#x5B;$taxonomy] = $term-&gt;slug;
 }
} </pre>
<p>Chúc các bạn thành công !</p>
<p>The post <a href="https://hoangthuc.com/bo-loc-taxonomy-trong-admin-custom-post/">Thêm bộ lọc taxonomy trong admin custom post type</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hoangthuc.com/bo-loc-taxonomy-trong-admin-custom-post/feed/</wfw:commentRss>
			<slash:comments>50</slash:comments>
		
		
			</item>
		<item>
		<title>Xóa slug trên custom post và custom taxonomy: Phần 2</title>
		<link>https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-2/</link>
					<comments>https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-2/#comments</comments>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Fri, 17 Mar 2017 20:25:06 +0000</pubDate>
				<category><![CDATA[Custom post wordpress]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress nâng cao]]></category>
		<category><![CDATA[Taxonomy wordpress]]></category>
		<category><![CDATA[Thủ thuật wordpress]]></category>
		<category><![CDATA[wordpress nâng cao]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=483</guid>

					<description><![CDATA[<p>Nhằm giúp các bạn tối ưu đường dẫn 1 cách gọn nhất khi tạo các custom post mới. Mình có làm 1 tus cách xóa slug cho trang single và category khi tạo custom post, mà wordpress chỉ hổ trợ cho 2 loại là post và page. Phần 2 mình sẽ hướng dẫn về cách ẩn [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-2/">Xóa slug trên custom post và custom taxonomy: Phần 2</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><em>Nhằm giúp các bạn tối ưu đường dẫn 1 cách gọn nhất khi tạo các <strong>custom post</strong> mới. Mình có làm 1 tus cách xóa slug cho trang single và category khi tạo custom post, mà wordpress chỉ hổ trợ cho 2 loại là post và page.</em></p>
<p>Phần 2 mình sẽ hướng dẫn về cách ẩn slug trên taxonomy custom post khi show bài viết. Các bạn nào chưa xem phần 1 hướng dẫn về cách<strong><a href="https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-1/" target="_blank" rel="noopener"> ẩn slug trên custom post</a>.</strong></p>
<p>Phần này mình sẽ hướng dẫn theo 2 cách , thứ nhất là dung hook trong code wordpress, hai là dùng plugin wordpress. Cách 2 có thể dùng dễ dàng cho các bạn không rành về code wordpress.</p>
<p><strong>1.Dùng hook request để ẩn slug taxonomy</strong></p>
<pre class="brush: php; title: ; notranslate">

add_filter('request', 'rudr_change_term_request', 1, 1 );

function rudr_change_term_request($query){

$tax_name = 'report_category';
if( $query&#x5B;'attachment'] ) :
$include_children = true;
$name = $query&#x5B;'attachment'];
else:
$include_children = false;
$name = $query&#x5B;'name'];
endif;
$term = get_term_by('slug', $name, $tax_name);

if (isset($name) &amp;&amp; $term &amp;&amp; !is_wp_error($term)):

if( $include_children ) {
unset($query&#x5B;'attachment']);
$parent = $term-&gt;parent;
while( $parent ) {
$parent_term = get_term( $parent, $tax_name);
$name = $parent_term-&gt;slug . '/' . $name;
$parent = $parent_term-&gt;parent;
}
} else {
unset($query&#x5B;'name']);
}

switch( $tax_name ):
case 'category':{
$query&#x5B;'category_name'] = $name; // for categories
break;
}
case 'post_tag':{
$query&#x5B;'tag'] = $name; // for post tags
break;
}
default:{
$query&#x5B;$tax_name] = $name; // for another taxonomies
break;
}
endswitch;

endif;

return $query;

}

</pre>
<p>Note* Trong phần này mình dùng hàm <strong>rudr_change_term_request</strong> để filter hook <strong>request</strong></p>
<p><strong>2. Dùng plugin wp htaccess contro</strong>l</p>
<p>Các bạn vào setting &gt;&gt; htaccess control</p>
<p><img decoding="async" class="aligncenter size-full wp-image-485" src="https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_031902-hoangthuc.jpg" alt="" width="1177" height="572" srcset="https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_031902-hoangthuc.jpg 1177w, https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_031902-hoangthuc-300x146.jpg 300w, https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_031902-hoangthuc-900x437.jpg 900w" sizes="(max-width: 1177px) 100vw, 1177px" /></p>
<p>Chọn Remove Taxonomies and author base sau đó tắt các slug taxonomy mà bạn muốn.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-486" src="https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_032127-hoangthuc.jpg" alt="" width="943" height="555" srcset="https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_032127-hoangthuc.jpg 943w, https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_032127-hoangthuc-300x177.jpg 300w, https://hoangthuc.com/wp-content/uploads/2017/03/2017-03-18_032127-hoangthuc-900x530.jpg 900w" sizes="(max-width: 943px) 100vw, 943px" /></p>
<p>Sau đó save lại. nếu vẫn chưa hoạt động các bạn vào setting &gt;&gt; permalink bấm  save lại.</p>
<p style="text-align: center;">Chúc các bạn thành công !</p>
<p>&nbsp;</p>
<p>The post <a href="https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-2/">Xóa slug trên custom post và custom taxonomy: Phần 2</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-2/feed/</wfw:commentRss>
			<slash:comments>49</slash:comments>
		
		
			</item>
		<item>
		<title>Xóa slug trên custom post và custom taxonomy: Phần 1</title>
		<link>https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-1/</link>
					<comments>https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-1/#comments</comments>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Sat, 11 Mar 2017 02:51:34 +0000</pubDate>
				<category><![CDATA[Custom post wordpress]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress nâng cao]]></category>
		<category><![CDATA[Custom post wp]]></category>
		<category><![CDATA[Thủ thuật wordpress]]></category>
		<category><![CDATA[wordpress nâng cao]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=476</guid>

					<description><![CDATA[<p>Nhằm giúp các bạn tối ưu đường dẫn 1 cách gọn nhất khi tạo các custom post mới. Mình có làm 1 tus cách xóa slug cho trang single và category khi tạo custom post, mà wordpress chỉ hổ trợ cho 2 loại là post và page. Đầu tiên về custom post (nếu bạn nào chưa [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-1/">Xóa slug trên custom post và custom taxonomy: Phần 1</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><em>Nhằm giúp các bạn tối ưu đường dẫn 1 cách gọn nhất khi tạo các <strong>custom post</strong> mới. Mình có làm 1 tus cách xóa slug cho trang single và category khi tạo custom post, mà wordpress chỉ hổ trợ cho 2 loại là post và page.</em></p>
<p>Đầu tiên về <strong><a href="https://hoangthuc.com/wordpress-nang-cao-1-custom-post-type/" target="_blank" rel="noopener">custom post</a></strong> (nếu bạn nào chưa biết về custom post có thể xem bài viết trước của mình).</p>
<p><strong>1.Xóa slug trên custom post trong trang single:</strong></p>
<p>Link custom post single ban đầu: https://hoangthuc.com/report/bao-cao-thu-chi/</p>
<p>Link custom post single cần thay thành: https://hoangthuc.com/bao-cao-thu-chi/</p>
<p>Custom post type mình làm ở đây là &#8220;report&#8221; nếu làm bạn có thể tùy biến custom post này. Các bạn vào file fucntions.php và thêm đoạn code có định dạng bên dưới.</p>
<pre class="brush: php; title: ; notranslate">
// remove slug custom_post type
function na_remove_slug( $post_link, $post, $leavename ) {

    if ( 'report' != $post-&gt;post_type || 'publish' != $post-&gt;post_status ) {
        return $post_link;
    }

    $post_link = str_replace( '/' . $post-&gt;post_type . '/', '/', $post_link );

    return $post_link;
}
add_filter( 'post_type_link', 'na_remove_slug', 10, 3 );
</pre>
<p>Note* Trong phần này bạn sẽ dung hàm <strong>na_remove_slug </strong>để filter vào hook<strong> post_type_link</strong></p>
<p><strong>2. Xữ lý lỗi 301 redirect khi chuyển:</strong></p>
<p>Trong quá trình remove slug như bước 1 wp sẽ xuất hiện lỗi 301 không tìm thấy trang. Cách xữ lý.</p>
<pre class="brush: php; title: ; notranslate">
function na_parse_request( $query ) {

    if ( ! $query-&gt;is_main_query() || 2 != count( $query-&gt;query ) || ! isset( $query-&gt;query&#x5B;'page'] ) ) {
        return;
    }

    if ( ! empty( $query-&gt;query&#x5B;'name'] ) ) {
        $query-&gt;set( 'post_type', array( 'post', 'report', 'page' ) );
    }
}
add_action( 'pre_get_posts', 'na_parse_request' );
</pre>
<p>Sau đó các bạn và <strong>Setting</strong> =&gt; <strong>Permalink</strong> và <strong>Save button</strong> lại để hoàn tất.</p>
<p>&nbsp;</p>
<p style="text-align: center;">Chúc các bạn thành công !</p>
<p>&nbsp;</p>
<p>The post <a href="https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-1/">Xóa slug trên custom post và custom taxonomy: Phần 1</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hoangthuc.com/xoa-slug-tren-custom-post-va-custom-taxonomy-phan-1/feed/</wfw:commentRss>
			<slash:comments>49</slash:comments>
		
		
			</item>
	</channel>
</rss>
