wordpress-plugin

Contact Form 7: use hook created using wpcf7_before_send_mail for only one contact form by id

你离开我真会死。 提交于 2019-11-30 09:12:10
I am working on a site with several forms created using Contact Form 7. For one of these forms, I am passing variables that I collected using a hidden input field in the form. I am passing these variables into the email using the wpcf7_before_send_mail hook, but these values are passing into every email (I added dynamic variables as well as static text) Here's the code: add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' ); function wpcf7_add_text_to_mail_body($contact_form){ $values_list = $_POST['valsitems']; $values_str = implode(", ", $values_list); // get mail property

How can I use is_page() inside a plugin?

时间秒杀一切 提交于 2019-11-30 09:02:44
问题 I want my plugin to register a script only in a certain page. For example, inside my plugin file I want to write something like this: if (is_page()) { $pageid_current = get_the_ID(); $page_slug = get_post($pageid_current)->post_name; if ($page_slug == 'articles'){ wp_register_script('myscript', '/someurl/main.js'); } } But I get the error: is_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in

How to hook into Contact Form 7 Before Send

纵饮孤独 提交于 2019-11-30 08:51:40
I have a plugin I am writing that I want to interact with Contact Form 7. In my plugin I added the following action add_action add_action("wpcf7_before_send_mail", "wpcf7_do_something_else"); function wpcf7_do_something_else(&$wpcf7_data) { // Here is the variable where the data are stored! var_dump($wpcf7_data); // If you want to skip mailing the data, you can do it... $wpcf7_data->skip_mail = true; } I submitted the contact form but the add_action I had did nothing. I'm unsure how to make my plugin intercept or do something when Contact Form 7 does something. Any, help on how to do this? I

Wordpress: Accessing A Plugin's Function From A Theme

十年热恋 提交于 2019-11-30 08:31:47
问题 I'm trying to add some functionality from a plugin I have made into a Wordpress theme but I am having little joy. The documentation doesn't really help me solve the problem so perhaps someone here can help. I have a plugin in Wordpress that is activated and working fine. The class for this plugin has a function called generateHtml which I would like to access from a Wordpress Theme. But whatever I try, I cannot seem to access my plugin's code. Can either give me a summary of what I need to do

Inserting a post in Wordpress using MySql

霸气de小男生 提交于 2019-11-30 06:25:10
问题 Does anyone know how to insert a new post into Wordpress using sql? 回答1: You can use the Post object: // Create post object $my_post = array(); $my_post['post_title'] = 'My post'; $my_post['post_content'] = 'This is my post.'; $my_post['post_status'] = 'publish'; $my_post['post_author'] = 1; $my_post['post_category'] = array(8,39); // Insert the post into the database wp_insert_post( $my_post ); More info found here. 回答2: Your question asks how to insert a new post into WordPress using SQL.

Wordpress - get post based on meta field content

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 05:55:05
I'm developing a wordpress plugin. I'm using two different custom post types, players and teams . Players has relevant meta fields: First name, last name, and team. Teams has relevant meta fields of team name. While editing a specific team post, I'm trying to have an array of all the players that currently have that team's name posted to their meta field for team name. I'm not sure how to do this. Any help or articles would be really helpful. Thanks The important thing is that you are querying for posts using at least the three criteria of the post type, meta key, and meta value. For example,

Custom post status not appearing

喜夏-厌秋 提交于 2019-11-30 04:43:44
问题 I am building a directory theme for a client of mine, and I like to add the feature of expiration in the posts by modifying the post status from publish to expired. To achieve that, I am trying to register a new post status by using the following code: add_action('init', 'registerStatus', 0); function registerStatus() { $args = array( 'label' => _x('Expired', 'Status General Name', 'z' ), 'label_count' => _n_noop('Expired (%s)', 'Expired (%s)', 'z'), 'public' => true, 'show_in_admin_all_list'

WordPress and Call to undefined function add_menu_page()

十年热恋 提交于 2019-11-30 01:20:49
问题 I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling: add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); However when I try this in my plugin setup file it tells me that the function is undefined: PHP Fatal error: Call to undefined function add_menu_page() This seems like a very simple thing

How do I add an HTML attribute to row (WP Bakery Visual Composer)?

北慕城南 提交于 2019-11-29 23:31:41
问题 I am trying to add an ID attribute to row in Visual Composer via documented function vc_add_param() in such a way: $attributes = array( 'type' => 'textfield', 'heading' => "HTML ID", 'param_name' => 'el_id', 'value' => '', 'description' => __( "Assign an ID to the row", "discprofile" ) ); vc_add_param( 'vc_row', $attributes ); ID field appears when I edit a row. I set a value, save it, save page, view it, but there is no affect to frontend. A row still has no ID attribute. I've also tried use

How to filter WooCommerce products by custom attribute

依然范特西╮ 提交于 2019-11-29 21:26:16
I'm trying to filter WooCommerce product archive by custom attributes. For example, there are 5 products with attribute "color" containing "red", and another 3 with attribute "color" containing "blue". How can I apply a filter to the products loop, so only the products containing "red" will be shown? Thanks On one of my sites I had to make a custom search by a lot of data some of it from custom fields here is how my $args look like for one of the options: $args=array('meta_query'=>$meta_query,'tax_query'=>array($query_tax),'posts_per_page' => 10,'post_type' => 'ad_listing','orderby'=>$orderby,