WordPress pages from custom table

I have custom table “catalog” inside wordpress database:


I have template file “catalog” and page “Catalog” where i show all items from catalog table. But how i can show single item from this list as a page?

domain.dev/catalog/ (this part works)
domain.dev/catalog/my-single-item-page (this i can’t figure out how to make to work)

how i can use “my-single-item-page ” as dynamic variable?

slug = “my-single-item-page”;

i have this snippet inside my functions.php file

function add_query_vars_catalog_item_filter( $vars ) {
$vars[] = “catalog_item”;
return $vars;
add_filter( ‘query_vars’, ‘add_query_vars_catalog_item_filter’ );

function catalog_rewrite() {
add_rewrite_rule(‘^catalog/([w-]+)/?’, ‘index.php?pagename=catalog&catalog_item=$matches[1]’, ‘top’);
add_action(‘init’, ‘catalog_rewrite’);

but when i go to domain.dev/catalog/some-my-item i got 404 page

I use this custom table because i generate form CSV. And in future it will be simpler for regenerate data

Read more here:: WordPress pages from custom table

Leave a Reply

Your email address will not be published. Required fields are marked *