2

I want assigned a value to my posts what variable by the current post's id. Originally I want use custom post_meta for this, I think this is would been elegant, but when I run a query with this post_meta, my pageload will be horrible slow (4x-5x the basic time), because the sql query (I create an own index in my database for this post_meta, but this dont help for me)...

So, I read that, If I create a custom taxonomy, what have the same values, this will be fast, like tag queries. But I dont want that, if this custom taxonomy creates pages (domain(.)tld/taxonomy_name/taxonomy_slug)...

Can I create custom taxonomy without pages? So that this going to works like that a post_meta? Only a value, what queried?

1

It depends on what exactly you want, but you can play with public, publicly_queryable and other arguments when registering the taxonomy.

For example, with the following code, the taxonomy will have the user interface in the backend, but won't be public and WordPress won't generate a URL for each term:

add_action( 'init', 'register_custom_tax' );
function register_custom_tax() {
    register_taxonomy(
        'my-tax',
        'post',
        array(
            'public'  => false,
            'show_ui' => true
        )
    );
}
1

I always use this neat web tool to create my custom post types. Under "Options" you can configure not to use slugs: https://generatewp.com/post-type/

Alternatively you can add this to the array above (in answer 1):

'has_archive'           => false, // this works for post types

(edited by questioner): has_archive doesn't exist for taxonomies, in this case need to use the 'rewrite' and 'public' args. The full code, what perfectly works for me (so this taxonomy works like an post_meta, but superfast --> everything about this taxonomy false, because I set the values of this dinamically, when the post published, with wp_set_object_terms):

add_action( 'init', 'register_custom_tax' );
function register_custom_tax() {
    register_taxonomy(
        'costum-taxonomy-name',
        'post',
        array(
            'public'  => false,
            'show_ui' => false,
            'publicly_queryable' => true, // If I am dont silly, the taxonomy will not public, but queryable
            'show_in_menu' => false,
            'show_in_nav_menus' => false,
            'rewrite' => false, // THIS IS IT, WHAT REALLY RESTRICT THE TAXONOMY PAGES
            'hierarchical' => false
        )
    );
}
  • Thank you, your reply! Your answer in fact concerned for custom post types, but, because you write, I recheked my site and code, and just now realised, that my code wrong, because I dont use the 'rewrite', only the 'public' => false ... So, when I searched a document about your question, I find this link, with the perfect answer: core.trac.wordpress.org/ticket/26269 (I edited your answer) – Galgóczi Levente Jun 7 '18 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.