Missing argument 2 for mp_product(),

I've created a template mp_product.php which looks exactly like I want, except for the Warning: Missing argument 2 for mp_product()...

I added a sidebar, which only showed the content. Another post suggested adding
<?php mp_product_price(); ?>
<?php mp_buy_button(); ?>
But I still wasn't seeing my product name, so I added
<?php mp_product(); ?>.

I read another post that said the theme (mine is Inspired) wasn't passing $product_id. Is there a way to display the product name, content, price, options, and button and not get the warning—without having to customize the theme (which I don't have the experience to do)?

Thanks,
Patty

  • fiberlyone
    • WPMU DEV Initiate

    @aristath

    WP_DEBUG is not enabled.

    /**
    * For developers: WordPress debugging mode.
    *
    * Change this to true to enable the display of notices during development.
    * It is strongly recommended that plugin and theme developers use WP_DEBUG
    * in their development environments.
    */
    define('WP_DEBUG', false);

    Patty

  • aristath
    • Recruit

    The mp_product function is located on the marketpress-includes/template-functions.php file and is declared in that file like this:
    function mp_product($echo = true, $product_id, $title = true, $content = 'full', $image = 'single', $meta = true)
    so the arguments it accepts are these:
    1. $echo (defaults to true)
    2. $product_id (NO DEFAULT)
    3. $title (defaults to true)
    4. $content (defaults to 'full')
    5. $image (defaults to 'single')
    6. $meta (defaults to true).

    As you can see, all arguments in that function have a default, except the $product_id, which is the second argument.

    In your template you'll have to specify that.
    Line 140 in your mp_product.php file is now
    <?php mp_product(); ?>
    You should change that to
    <?php mp_product( true, $post->ID ); ?>

    I hope that helps!

    I am marking this issue as resolved.
    If however the above fix doesn't work for you or you need any further instructions/clarifications, don't hesitate to reopen it and post an update on your current status. :slight_smile:

    Cheers,
    Ari.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.