Woocommerce custom attributes not created, wc_create_attribute still working? - wordpress

Is there something i am missing?
I try to create a new custom attribute for plugin purpose, but somehow it doesnt work.
The simple function is as follows:
$data = array(
'name' => 'programmas',
'slug' => 'elearning_programmas',
'type' => 'select',
'order_by' => 'menu_order',
'has_archives' => 1
);
wc_create_attribute( $data );
However, whatever i do, no new attribute is created in the list with attributes under the product attributes page, neither available on the individual product page.
Any ideas?

Related

How to link custom field to shortcode?

I'm trying to link a custom field to a custom shortcode so the shortcode shows displays only the posts with the custom field selected to it.
This is my code below for my shortcode as you can see the key is my custom felid "flash_deal". When I enter the shortcode I just get all the perk psots and no the custom field perk posts?
add_shortcode('foundry_flash', 'shortcode_query_flash');
function shortcode_query_flash($atts, $content){
extract(shortcode_atts(array( // a few default values
'post_type' => 'perks',
'posts_per_page' => -1 ,
'meta_query' => array(
array(
'key' => 'flash_deal', // name of custom field
'value' => '"yes"', // matches exactly "red"
'compare' => 'LIKE'
)
)
), $atts));
The code you show is simply setting up variables - not running any queries at all (see extract documentation & shortcode_atts documentation).
I assume you have more code you just didn't add here, so likely the problem is the double quotes around yes that are causing issues. It's literally looking for "quoteyesquote".
As a general working example to get "Parks" Post based on custom meta, you need to use WP_Query as in the docs here.
$args = array(
'post_type' => 'parks',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'flash_deal',
'value' => 'yes',
'compare' => 'LIKE',
),
),
);
$query = new WP_Query( $args );
Then use a Nested Loop setup to loop through the results.

How to add a custom Rules "action" in Drupal?

I'm using the Rules module in Drupal 7, and I tried to add a new Rules "Action"
I followed the steps described in How to create an custom rule action using hook_rules_action_info? to create a custom rule action using hook_rules_action_info:
I tried to create a sample file (save_nid.rules.inc) in the folder /rules/module/.
And I also tried to create a module folder in /site/all/module/save_nid/.
My code in save_nid.rules.inc looks like so:
function rules_save_nid_action_info() {
return array(
'save_nid_action' => array(
'label' => t('Custom Action'),
'parameter' => array(
'param1' => array(
'type' => 'int',
'label' => t('Parameter Label'),
),
'param2' => array(
'type' => 'commerce_order',
'label' => t('Parameter Label2'),
),
),
'configurable' => FALSE,
'group' => t('ABC Custom module action'),
'callbacks' => array(
'execute' => 'abc_custom_action',
),
),
}
After I cleared the Drupal cache, I didn't see my "custom rule" in the list.
What am I missing or doing wrong?
In your case, the machine name of your custom module seems to be save_nid.
So if you want to use hook_rules_action_info in your module, your function needs to be named save_nid_rules_action_info, instead of rules_save_nid_action_info.
Not sure if it is the "only" problem why you can't get it to work, but at least it is "a" problem you need to address.
PS: make sure to save that custom coding in your custom module's folder (in /site/all/module/save_nid/).

Unable to edit a new Custom Taxonomy in Wordpress

I have just registered a new Custom Taxonomy in Wordpress (as per the docs). Here is a copy of the code in functions.php for reference:
function people_init() {
// create a new taxonomy
register_taxonomy(
'people',
'post',
array(
'label' => __( 'People' ),
'rewrite' => array( 'slug' => 'person' ),
'capabilities' => array(
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides'
)
)
);
}
add_action( 'init', 'people_init' );
As you can see in the image below, the Taxonomy appears within left-hand navigation but when my (admin) user clicks on the option I am displayed with an You are not allowed to edit this item. error:
Can anyone suggest why this may be?
Almost as soon as I posted this I realised it is the capabilities array. Removing this, so that it reverts to the default allows access as intended.
After further investigation I found that the following was the best settings to get this functioning correctly:
'capabilities' => array(
'manage__terms' => 'edit_posts',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts'
)

Wordpress custom post category

I am quit new to wordpress and have a problem I cannot seems to solve even with a day of google searching. This is what I did:
I have created a custom post type called lookbook. This works fine and I can add new items and such.
I added a taxonomy so I could add an category to it.
function lookbook_taxonomy() {
register_taxonomy( 'jeans','lookbook',
array(
'hierarchical' => true,
'label' => 'jeans',
'query_var' => true,
'rewrite' => true
)
);
}
Using wp_query or query_posts I can retrieve the lookbook items and display their content.
(problem) When I pres the category link provided by word press the page just goes back to index. The link changes to the desired filter however NO post are being filtered. I tried all kinds of stuff but I can seems to find a way to just press the category link and just diplay those post.
update: (code I used to register post type)
add_action('init', 'lookbook_register_post_type');
function lookbook_register_post_type() {
register_post_type('lookbook', array(
'labels' => array(
'name' => __('lookbook'),
'singular_name' => __('lookbook')),
'public' => true,
'capability_type' => 'post',
'supports' => array(
'title',
'excerpt'
),
'has_archive' => true,
'taxonomies' => array('category','post_tag')
)
);
}
You'll need to add 'has_archive' => true to your register_post_type arguments array if it's not already there.
Additionally, make sure you have the necessary template files ready. Read up on Wordpress' Template Hierarchy.
If you show us the code you used to register the post type, as well as what code makes up "the category link", we might be of more help!

Create a page to edit all fields from a custom content type (D7)

I have a custom content type that has a custom field called [stock]
I would like to have a single page that shows me ALL nodes [stock] values in a list and allows me to change the value. Is this possible?
Any advice would be much appreciated
Well I was going to write a module to this but as usual with Drupal someone beat me to it!
You should download and install Views, and also the (quite frankly excellent) Slick Grid module. It provides a view type (Slick Grid) that will create a table of content, with inline editing enabled for fields. For more complex field types it provides a modal popup for editing instead.
It took me 10 minutes to create a view with the following output, which lets me edit fields directly in the table by double clicking on the cell:
The content is saved automatically to the database when you click off the edit cell again, and it's all handled via AJAX which makes it very pleasant to use.
You can add as many fields as you like to the grid so I think this is exactly what you're after :)
Yes it is I have done something like this to get it working. In your case you would have to modify the sql query to fetch your custom field. You also would need to modify the $headers and the $rows array(s) to include what you need to display, but I think you get the idea.
// first I create my own module hooking the menu
function custom_menu() {
$items['admin/custom-content'] = array(
'title' => t('Custom Content'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('access content'),
);
$items['admin/custom-content/product'] = array(
'title' => t('Products'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('access content'),
'page callback' => 'custom_view_products'
);
return $items;
}
// the above will add a new admin menu link called Custom Content
// then I have a callback method for the menu item
function custom_view_products() {
// setup the header for the form
$headers = array(
array('data' => 'Title', 'field' => 'title', 'sort' => 'asc'),
array('data' => 'Published')
);
//
$query = "SELECT n.* FROM {node} n ".
"WHERE n.type = 'product' ORDER BY n.title ASC";
//
$rows = array();
if(($results = db_query($query)->fetchAll())) {
foreach ($results as $node) {
$rows[] = array(
'data' => array(
l($node->title, 'node/'. $node->nid .'/edit'),
$node->status
), 'class' => array('published')
);
}
}
$html = theme('table',
array(
'header' => $headers,
'rows'=>$rows,
'caption' => '',
'sticky' => FALSE,
'empty' => 'No products located...',
)
);
return $html;
}

Resources