<?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 wp Archives - Hi You, I am Tade</title>
	<atom:link href="https://hoangthuc.com/tag/custom-post-wp/feed/" rel="self" type="application/rss+xml" />
	<link>https://hoangthuc.com/tag/custom-post-wp/</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 wp Archives - Hi You, I am Tade</title>
	<link>https://hoangthuc.com/tag/custom-post-wp/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<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>
