How to make qTranslate supports Custom Post Types?

How to make qTranslate supports Custom Post Types?

add this code in
wp-content/plugins/qtranslate/qtranslate_hooks.php

on line 303

add_filter('post_type_link','qtrans_convertURL');//fix custom post type URL

update:(20/06/2013)

Congrats to Qian Qin for writing some easily extensible code!

Here’s a relatively simple way of adding translations your own custom taxonomies.
Assuming you’ve registered a taxonomy, ‘my_cat’, add these two lines into qtranslate_hooks.php,
near the end of the file around line 244 (search for ‘// Hooks (Actions)’ in the file).

// Custom Taxonomies
add_action(‘my_cat_add_form’, ‘qtrans_modifyTermFormFor’);
add_action(‘my_cat_edit_form’, ‘qtrans_modifyTermFormFor’);

for example i am working on theme called increase it uses custom post type called Projects i looked in the functions and found the categories name is pj-sort-categs
so i added this line to the hooks

//increase projects
add_action(‘pj-sort-categs_add_form’, ‘qtrans_modifyTermFormFor’);
add_action(‘pj-sort-categs_edit_form’, ‘qtrans_modifyTermFormFor’);

and it showed me the languages to the custom post type Categories .

Advertisements

30 thoughts on “How to make qTranslate supports Custom Post Types?

  1. JouTheLux says:

    In my wp only works in taxonomies but not in post_type. Any idea?

    This is my code:

    $labels = array(
    ‘name’ => _x( ‘Receptes’, ‘Recipe name’ ),
    ‘singular_name’ => _x( ‘Recepte’, ‘Recipe type singular name’ )
    );

    //register the recipe category taxonomy
    register_taxonomy( “ingredient”,
    array( “recipe” ),
    array( “hierarchical” => true,
    “label” => “Ingredients”,
    “singular_label” => “Ingredients”,
    “rewrite” => array(“slug” => “ingredient”),
    “query_var” => true,
    ‘has_archive’ => true

    ) );

    //register the recipe custom post type
    register_post_type( ‘recipe’,
    array( ‘labels’ => $labels,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘capability_type’ => ‘post’,
    ‘hierarchical’ => false,
    ‘rewrite’=>array( ‘slug’=>’recipe’, ‘feeds’=>false, ‘pages’=>false ),
    ‘taxonomies’ => array( ‘ingredient’ ),
    ‘supports’ => array( ‘title’, ‘custom-fields’, ‘thumbnail’ ) ) );

    add_action( ‘recipe_add_form’, ‘qtrans_modifyTermFormFor’);
    add_action( ‘recipe_edit_form’, ‘qtrans_modifyTermFormFor’);
    add_action( ‘ingredient_add_form’, ‘qtrans_modifyTermFormFor’);
    add_action( ‘ingredient_edit_form’, ‘qtrans_modifyTermFormFor’);

  2. Hello, I have a problem with the portfolio and blog links on my site displaying the right pages. if you choose to browse the website in English language and you are in the portfolio section, when you click on one of the sections it displays the gallery in the default language which is Spanish when it should show it in English. I tried adding the code mentioned above to the qtranslate_hooks.php file. But I am not sure how to register the taxonomies thou. Any assistance with this would be very helpful.
    Thanks!

    • if u can send me the theme or the link i need to see the functions.php of theme or the function that makes the portfoilio u can add me on skype was955 and i can help live if u want ๐Ÿ™‚

        • well after downloading the theme and setting it up and installing data and qtranslate and working on the code to see the problem i managed to make it work great

          i played with qtranslate settings and added dome hooks like this

          add_filter(‘post_type_link’, ‘qtrans_convertURL’);

          u can ask me if u need me to show u what to do

  3. Hi !
    Is this suppose to add a language field in the wordpess admin ui ? (just like for categories translation ?)

    Thanks for the answer ๐Ÿ˜›

      • Haha that was a quick answer ๐Ÿ˜€
        I definitely need help, It seems so simple and I don’t see anything ?

        Can it work with plugin ? Like WCK or Simple Taxonomies ?

        I’m still trying but if it doesn’t work, sure i will contact you. Thanks for you help ๐Ÿ™‚

  4. Hi! I’m using a calendar plugin named The Geek Event and it uses custom post types to manage the events. You can see how it works here: http://confucio.uv.es

    The problem is that qtranslate doesn’t translate custom post types. Should I just add this line to the qtranslate_hooks.php file?

    add_filter(‘post_type_link’,’qtrans_convertURL’);//fix custom post type URL

    For some reasons I can’t modify the code all the times I want, so I want to make sure that’s what I need before I add it.

    Thank you so much!

  5. Petter says:

    It works for when creating new CPT Categores, but not editing existing ones. Could someone help me with that?

Leave a Reply :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s