0

I'm writing a custom script to call via url, passing a parameter via GET. This script shold take the GET variables and made a wp_post. I have problem getting the taxonomies right for the post, keep getting invalid taxonomies. I think it's because I run the script from the functions.php before the register of taxonomies are done, but this is my functions.php:

require( get_template_directory() . '/includes/custom-posts.php' );
/* .... */
if ( isset($_GET['v'])) {
    $url = $_GET['v'];  

   $taxonomy_names = get_post_taxonomies(198);
   print_r( $taxonomy_names );
}

and this is the custom-posts.php

add_action( 'init', 'ts_create_taxonomy_videos', 0 );
function ts_create_taxonomy_videos(){
    $slug = get_option('videotouch_general');
    $slug = (isset($slug['slug_video_taxonomy'])) ? $slug['slug_video_taxonomy'] : 'videos_categories';

    $labels = array(
        'name' => __( 'Category', 'touchsize' ),
        'singular_name' => __( 'Video', 'touchsize' ),
        'search_items' =>  __( 'Search Videos', 'touchsize' ),
        'popular_items' => __( 'Popular Videos', 'touchsize' ),
        'all_items' => __( 'All Videos', 'touchsize' ),
        'parent_item' => __( 'Parent Videos', 'touchsize' ),
        'parent_item_colon' => __( 'Parent Videos:', 'touchsize' ),
        'edit_item' => __( 'Edit Videos', 'touchsize' ),
        'update_item' => __( 'Update Videos', 'touchsize' ),
        'add_new_item' => __( 'Add New Videos', 'touchsize' ),
        'new_item_name' => __( 'New Videos Name', 'touchsize' ),
    );
    register_taxonomy('videos_categories', array('videos_categories'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => $slug ),
    ));
}

I'm tring to getting the taxonomies of an already exist post so I can copy that. for my new one. But I tryed to insert the post with the taxonomies but doesn't work either

  • I don't think so that functions.php is the right place to put this code:: /* .... */ if ( isset($_GET['v'])) { $url = $_GET['v']; $taxonomy_names = get_post_taxonomies(198); print_r( $taxonomy_names ); } – BlueSuiter Apr 14 '17 at 8:33
  • You should put it wherever you want to show the posts...put it in a function and call that function there – BlueSuiter Apr 14 '17 at 8:34
  • This is a script called from url that create a new post arbitrarily so I'm not doin i theloop os inside the theme init. – Kreker Apr 18 '17 at 13:23
  • 1
    I solved this reregistering the taxonomy inside the function. – Kreker Apr 20 '17 at 13:28

Your Answer

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

Browse other questions tagged or ask your own question.