Use Wordpress custom post in a contact form - wordpress

I have created custom post type "Product" in Wordpress and I would like to use Products within my contact form. For example, I would like to have a drop down that is a list of all of my Products so users can select a Product name as the message's Subject. I have Contact Form 7 installed. Is there an easy way to do this?
Thanks !

I think the short answer is no. There is not an easy way to do this. The Contact Form 7 plugin uses shortcodes to construct the select lists. What you need to do is run a query on your Posts -> Products and generate your own select list. I suppose what I would do is write my own shortcode function. Then you can include it in your page.
[myProductsShortCode]
Then you can iterate through that result set and generate your own select list.
http://codex.wordpress.org/Shortcode_API
http://codex.wordpress.org/wpdb#query_-_Run_Any_Query_on_the_Database

People seem to be able to add custom information like that, from
function test_generator() {
/* need to produce html like this:
<span class="wpcf7-form-control-wrap menu-645"><select name="menu-645" class="wpcf7-select"><option value="one">one</option><option value="two">two</option></select></span>
so here we go: */
$list = "<span class=\"wpcf7-form-control-wrap menu-test\"><select name=\"menu-test\" class=\"wpcf7-select\"><option value=\"test1\">test-1</option><option value=\"test2\">test-2</option></select></span>";
return $list;
}
wpcf7_add_shortcode('test', 'test_generator');
and then just use [test] in the contactform

Related

show added to cart message in woocommerce

As mentioned above I want to display "product added to cart message" in woocommerce.
I know there is some kind of built in function
wc_add_to_cart_message()
If I paste it in index page together with
wc_print_notices();
Like this:
wc_add_to_cart_message('products');
wc_print_notices();
wc_add_to_cart_message('products');
wc_print_notices();
then my current output is:
“” has been added to your cart.
My desired output is that it would return that particular product name together with a message.
but what would be the proper way of using it?
Or is there some other way?
In that function you actually have to give product id or array of product ids, so your line should look like:
wc_add_to_cart_message($product_id);

Views hierarchical taxonomy select box

I'm trying to create a Drupal web for a travel agency and need your help.
I store locations in a taxonomy with hierarchy, the structure looks like this:
Europe
France
Paris
Germany
Berlin
I'm using a view with "Has taxonomy terms (with depth)" filter, exposed as a selectbox.
"Show hierarchy in dropdown" is enabled
It works fine, but the selectbox starts to get pretty huge as the number of the location is increasing.
So my question is:
Is it possible to show just the 1st and 2nd level of the taxonomy in the select box?
Or is it possible to show each level of the taxonomy in a separate select box?
Thank you!
Use hierarchical select module to create select list. This will give you a hierarchy with '-' symbol in front all child elements.
Then you can alter the form with hook_form_alter function.
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if (($form_id == 'your_form_id')) {
foreach ($form['tid']['#options'] as $term_key => $term) {
// Check if this is a child by looking for '-' as first char in string
$term_value = reset($term->option);
if($term_value[0] == '-') {
unset($form['tid']['#options'][$term_key]);
}
}
}
}
You should check this link. I am pretty sure, you will be able to it by some custom coding in any custom module or template.php
You can check this module too, really helpful.
Thanks
"is it possible to show each level of the taxonomy in a separate select box?"
The only module I have seen that might be useful to you is the Hierarchical Select module. http://drupal.org/project/hierarchical_select

how to extend default search to include the data of plugin?

i want to carry out the search in my custom plugin table .i.e. when i search for some keyword or phrase, it should search in my custom table too.
And if the data is from my custom table then it should carry out my plugin function to display data.
Don't know whether it was a good solution or not but i did it by myself. See below :
i added search.php to my default theme
after the if condition of have_posts and before else part mean in
between i inserted my code
elseif (pdfsearch_result($_GET['s'])):
$search_pdf = mysearch_result($_GET['s']); // my search function to search for my plugin data
and then did formatting and achieved the desired result. Hope this may help someone, but do post if there is better way of doing this.

Drupal - Views. Setting a filter programmatically

I hope this is not a stupid question I have been searching for most of the day!
I have a Content Type (Documents) which simply contains a title, file and a category. The category value is required and is 'powered' by Taxonomy.
I now wish to create a view which will display these documents grouped and titled by the taxonomy term.
Using my limited Drupal knowledge I intent to iterate through the relevant terms IDs (using taxonomy_get_tree($vid)) and then render each view accordingly.
To do this I have been hoping to use this snippet.
view = views_get_view('documents');
$view->set_display($display_id);
$filter = $view->get_item($display_id, 'filter', 'field_dl_category');
$filter['value']['value'] = $filter_value;
$view->set_item($display_id, 'filter', 'field_dl_category', $filter);
$viewsoutput = $view->render();
But this is not working; when I query the value of the $filter ($view->get_item($display_id, 'filter', 'field_dl_category')) I get null returned.
Might this be that my filter name is not the same as the CCK field name?
I am using Drupal 7.
Any help much appreciated, I am running out of ideas (and time).
I finally managed to get this working but I took a slightly different approach.
I changed my view and added the relevant contextual filter and then used this function views_embed_view to get at my required results.
If this helps! this is my solution:
$display_id = 'default';
$vid = 7;
$terms = taxonomy_get_tree($vid);
foreach($terms As $term){
$content = views_embed_view('documents', $display_id, $term->tid);
//now we see if any content has been provided
if(trim($content) != ''){
print "<h3>" . $term->name . "</h3>";
print $content;
}
}
In my case the trim($content) returns '' with no data as the view template has been edited, this might not be the case for all.
I am a very new Drupal developer so I'm sure there are much better ways of doing this, if so please do post.
I am going to go ahead and assume that you want to show, using Views, a list of document nodes grouped by the category that they have been tagged with.
There are two (of maybe more) ways by which you can do this in Views 3:
(a) Choose a display style that allows you to select a Grouping field. (You could try the table style that ships with Views by default). Suppose you have properly related the node table to the taxonomy_term_data table through a Views relationship, you could choose taxonomy_term_data.name as the grouping field.
Note that this grouping is done before the view is just rendered. So, your query would just have to select a flat list of (content, tag) pairs.
(b) You could also make use of the Attachment display type to achieve something similar. Show the used categories first in a list view clicking on which will show a page (attachment) with all documents tagged in that chosen category.
To understand how to do (a) or (b), turn on the advanced_help module (which is not a Views requisite but is recommended) first.
For (a), read the section on Grouping in styles i.e. views/help/style-grouping.html and
For (b), read the section on Attachment display i.e. views/help/display-attachment.html
A couple of things about your approach:
(a) It will show all terms from that vocabulary irrespective of whether or not they were used to tag at least one document.
(b) views_embed_view() will return NULL even if the currently viewing user does not have access to the view. So, ensure that you catch that case.
Here's an alternative:
$view = views_get_view('view_machine_name');
$view->init_display('default');
$view->display_handler->display->display_options['filters']['your_filter_name']['default_value'] = 'your_value';
$view->is_cacheable = FALSE;
$view->execute();
print $view->render();
I know you can probably set this using some convoluted method and obviously that would be better. But if you just want a quick and dirty straight access without messing around this will get you there.

order post taxonomies alphabeticaly in wordpress?

I'm using a custom taxonomy for my posts which I print like this:
the_terms(get_the_ID(), 'sizes', '<p>', ', ', '</p>');
This works fine but it prints the terms in the order they were added, is there a way to make it print alphabeticaly? the_terms function doesn't let me pass any order parameter so I guess I have to use a different one but I haven't found any yet.
Thanks in advance.
the_terms() is using get_term_list, to retrive the taxonomy ( http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/category-template.php#L932 ) for the code.
You have the option to use a filter here, but it is applyed to the HTML generated for every single term (taxonomy1). Not the best option to sort.
Best is use the function get_the_terms() , sorting the results and constructing the output list by yourself!

Resources