I am trying to create category from WordPress plugin. Here is my code:
$id = wp_create_category('Category_name', 2);
But i am getting this
error:
Missing argument 4 for wp_insert_term(), called in taxonomy.php on line 144 and defined in taxonomy.php on line 2226
But i am not using function wp_insert_term() anywhere. Please help me. What i am doing wrong? is there anything extra which i have to do in plugin to make it working?
Thanks in advance
try to use wp_insert_category as wp_create_category is just a wrapper for it.
Passing a category ID means you're trying to create a child category, so make sure that a category with and ID of 2 exists.
If you do have a category with an ID of 2, try omitting that param and seeing what happens. If your still getting an error after that, check what version of PHP you are using and update it.
If you're making a plugin to add a category to the database you will be better off using wp_insert_category() as it gives you more control.
Related
I want to trigger an event when a category is added or deleted.
So I think the add_action i look for are these
create_category
delete_category
(got them from here source)
In the Event I want to have a function where the ID and the name of the category is sent to me.
At the moment I am struggling with the delete operation. The Id seems to delivered properly. The category "name" unfortunately not.
My guess is at the moment that the database no longer contains the name of the category. Probably because the delete_category is invoked after the job is already done. Therefore "get_cat_name()" might not work. Unfortunately I could not find some kind of "pre_delte_category" action.
Here are the functions i placed as hooks in my functions.php of my theme:
function event_by_add_cat($category_id){
$name = get_cat_name($category_id);
send_me_mail_add($name, $category_id);
}
add_action('create_category', 'event_by_add_cat');
function event_by_del_cat($category_id){
$name = get_cat_name($category_id); // is name already to far gone?
send_me_mail_del($name, category_id);
return;
}
add_action('delete_category', 'event_by_del_cat');
The function send_me_mail_add(name, id) does work.
It seems that the function is send_me_mail_del(name, id); is not called correct. Unfortunately WP shows me no Errors.
Thank you for your help :)
Unfortunately it's not possible to get the name that way, as you guessed, the name is already deleted and there is no 'pre' hook.
You could work arround that by hooking a function to the creation of categories, that adds the name to a different table in the database, togehter with the ID.
And then, if the category gets deleted, you can look the name up there and then also delete it afterwards.
hi i create one custom page in WordPress like page-download.php
i access this page like
http://example.com/download
its word fine but i want access this page like
http://example.com/download?n=skype
http://example.com/download?n=firefox
etc every time n value change.
and also i want get n value in page-download.php
please tell me how to do it . i know how to work in php simple but in wordpress its not work
Why just not use, echo $_GET['n'] ?
When you hit this page directly from the URL like below, please change your parameter, because of that I have tried same method few days ago and I can't get the parameter value.
http://example.com/download?from_browser=skype
http://example.com/download?from_browser=firefox
You can get the value like below or as per the reference :
$blah = get_query_var( 'from_browser');
if(isset($blah)) // Your code will be here
Hope this help!!!
I am new to Opencart, so please help.
I edited product/product.php controller and managed to pass manufacturer_id to product/product.tpl.
Now I am stuck on quickcheckout/checkout. I need to know how to fetch product's manufacturer_id and pass it to shipping_method (view or controller, but I would prefer controller) inside quickcheckout/checkout.
Thank you
Here's how I ended up doing it (I know it's not optimal, but it works).
In \system\library\cart.php, at line 45, after $product_query = $this->db->query("SELECT * FROM... I added:
$GLOBALS['cart_manufacturer_id'] = $product_query->row['manufacturer_id'];
I fetch that in \catalog\view\theme\eagency\template\quickcheckout\checkout.tpl using a global previously defined in cart.php, and finally, send it to \catalog\controller\quickcheckout as a URI param (I am using AJAX), thus:
$.ajax({
url: 'index.php?route=quickcheckout/shipping_method&ncal_cart_manufacturer_id=<?php echo $GLOBALS['cart_manufacturer_id']; ?>'
I know this is far of optimal, but since I didn't have time to learn Opencart, I just came up with something that worked.
In any case, I hope I'll help someone.
Is there any way to find page by id in layout file. I'm currently using
$this->fuel->pages->find(5)
But its not working. I'm getting following error message
Plugin module can not be found, maybe you forgot to bind it if it's a
custom plugin ?
You have to use an array to pass parameters in the method and you can use the find_one.
$this->fuel->pages->find_one(array('where' => array('id' => 5)))
I am currently making a module that requires me to take an order object and make it reorder itself.. thus, creating a new order in the backend with the exact same items and credentials.
This is the code that i have thus far… it doesn’t seem to reorder the item or create and add another backend order.
$personsOrder = Mage::getModel(’sales/order’);
$personsOrder->loadByIncrementId($order[’model_order_id’]);
$order_model = Mage::getSingleton(’adminhtml/sales_order_create’);
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
/*
$order_model->save();
$order_model->place();
$order_model->sendNewOrderEmail();
*/
Any help is greatly appreciated!!
$orderId= $YOUR_ORDER_NUMBER;
$personsOrder = Mage::getModel('sales/order')->load($orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
$order_model->createOrder();
My first thought is that you should be using $order->getIncrementId() on line 2 rather than $order['model_order_id'], but I'm not sure where you're getting $order from in the first place. Have you checked that $order['model_order_id'] is actually returning a valid increment ID? I don't see model_order_id as a field in the database anywhere...
I'd be suggesting that you getting your IDE and XDebug working so that you can inspect the objects as you work with them and understand what's going on.
Cheers,
JD
If the order that you have placed the first time around is also created through coding and not from store front then you need to make sure that you have added an entry in the sales_flat_quote_item table. Otherwise that order cannot be reordered. So make sure it's not the case with your order creation.