Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im Getting a couple of warnings when creating custom post types, someone referred me to using a plug in but since i'm new to this i want to know what is going on so i want to do it manually. This are the warnings i get.

Warning: Missing argument 2 for _x(), called in C:\xampp\htdocs\wordpress\wp-content\themes\posttypes.php on line 8 and defined in C:\xampp\htdocs\wordpress\wp-includes\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\xampp\htdocs\wordpress\wp-content\themes\posttypes.php on line 9 and defined in C:\xampp\htdocs\wordpress\wp-includes\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\xampp\htdocs\wordpress\wp-content\themes\posttypes.php on line 28 and defined in C:\xampp\htdocs\wordpress\wp-includes\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\xampp\htdocs\wordpress\wp-content\themes\posttypes.php on line 29 and defined in C:\xampp\htdocs\wordpress\wp-includes\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\xampp\htdocs\wordpress\wp-content\themes\posttypes.php on line 48 and defined in C:\xampp\htdocs\wordpress\wp-includes\l10n.php on line 189

Warning: Missing argument 2 for _x(), called in C:\xampp\htdocs\wordpress\wp-content\themes\posttypes.php on line 49 and defined in C:\xampp\htdocs\wordpress\wp-includes\l10n.php on line 189

Here is my code

<?php 

//Add new post type for Models
add_action('init', 'models_portfolio_init');
function models_portfolio_init()
{
    $args = array(
                    'label' => _x('Models'),
                    'singular_label' => _x('Models'),
                    'public' => true,
                    'publicly_queryable' => true,
                    'show_ui' => true,
                    'query_var' => true,
                    'rewrite' => true,
                    'capability_type' => 'post',
                    'hierarchical' => false,
                    'menu_position' => null,
                    'supports' => array('title','editor','comments')
                );
                register_post_type('recipes',$args);
}

//Add new post type for Books
add_action('init', 'books_posts_init');
function books_posts_init()
{
    $args = array(
                    'label' => _x('Books'),
                    'singular_label' => _x('Books'),
                    'public' => true,
                    'publicly_queryable' => true,
                    'show_ui' => true,
                    'query_var' => true,
                    'rewrite' => true,
                    'capability_type' => 'post',
                    'hierarchical' => false,
                    'menu_position' => null,
                    'supports' => array('title','editor','comments')
                );
                register_post_type('books',$args);
}

//Add new post type for Advertisements
add_action('init', 'advertisements_init');
function advertisements_init()
{
    $args = array(
                    'label' => _x('Advertisements'),
                    'singular_label' => _x('Advertisements'),
                    'public' => true,
                    'publicly_queryable' => true,
                    'show_ui' => true,
                    'query_var' => true,
                    'rewrite' => true,
                    'capability_type' => 'post',
                    'hierarchical' => false,
                    'menu_position' => null,
                    'supports' => array('title','editor','comments')
                );
                register_post_type('advertisements',$args);
}

?>
share|improve this question

2 Answers 2

up vote 2 down vote accepted

Wherever you're using _x('lorem'), use _x('lorem', 'models'); instead. Models is actually supposed to be a context, but I don't know your context, hence using models. Try this.

share|improve this answer
    
Ok, I actually checked the file l10n.php. Just added this _x( $text, $context, $domain = 'Models' ) and the warnings went away dumb of me for not checking that file earlier i'm guessing this changed on wordpress 3 –  Gore Oct 14 '11 at 17:40
    
Actually it just worked like you told me. Thank you very Much –  Gore Oct 14 '11 at 17:48
    
Glad it worked! You're welcome! –  Rutwick Gangurde Oct 14 '11 at 17:52

I'm trying to get this into a few places where the search on this ranks.

Based on the piece of code the OP has posted, he is working through the Lynda.com tutorial on custom post types. I've done that one and it does have a glitch in the latest version of WordPress but it's not WP's fault.

If subsequent help seekers find this post, they need to wait for the next chapter when:

$args = array(
    'label' => _x('Foos')
    'singular_label' => _x('Foo')

Becomes:

$args = array(
    'label' => _x('Foos', 'post type general name'),
    'singular_label' => _x('Foo', 'post type singular name')

At which point the second argument DOES exist and the error message goes away.

The OP is also calling:

    register_post_type('recipes',$args);

Instead of his new model_types definition, which is because the Lynda tutorial is based on a custom portfolio for a cook.

In the opening chapter, which generates the error, students can use the following version to eliminate the problem (remove the x, remove the second argument):

    $args = array(
        'label' => __('Foos')
        'singular_label' => __('Foo')

By simply eliminating the argument call, they invalidate the custom description of their label so it should be REPLACED in the final version. In fact, the tutorial will have you delete the original definitions as they are handled by an array later on.

So just change x( to _( and move along.

At any rate, I do hope this will help out future frustrated students.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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