INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
wordpress not able to open theme-editor.php I am having a site radhanath-swami.info. I logged as admin using "radhanath-swami.info/wp-admin". then i tried "radhanath-swami.info/wp-admin/theme-editor.php" You do not have sufficient permissions to access this page. I dont know what to do. I googled a lot but not much help. I dont have access to the server not the ftp. Whatever i can do is only from admin dashboard. I was using theme esplanade, due to some reasons i have changed to another theme. THen i have deleted the esplande theme. Later I have decided to use esplanade, so installed it again and activated it. From then the theme-editor.php is not working. Before this theme-editor.php was working. I also checked with changing to other theme. It also now shows the same permission thing when i open theme-editor.php I have also tried removing all the plugins still same message. I feel there are some bugs in the wordpress
You can try enable the theme editor via WP-Config as shown here: < It's probably impossible if you don't have FTP access - but its possible that the theme editor was enabled previously via the theme funcitons.php and has since been disabled once you re-installed a fresh version of it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "themes" }
turn off WooCommerce for a site in a multi site environment I've just installed P3 (Plugin Performance Profiler) and it shows that WooCommerce & WooCommerce Subscriptions are active on every one of my subdomain multi sites. How do I turn plugins off on on a site by site basis?
Plugins are not like Themes were you need to network activate them to make them available on each site. If you network activate a plugin, it will be switched ON for all network sites. If you wish to allow each site to decide if they wish to activate or deactivate the plugin, then network deactivate the plugin in network admin.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -3, "tags": "plugins, multisite" }
Show subpages of a category in a custom menu I have added a post category to a custom menu through Admin. But when it shows, it just shows the category name, and does not show the posts inside the category. Is there a way to add an args; that the children post pages will also show with the category title in the menu? This is my current function: function wp_nav_links() { wp_nav_menu( array( 'menu' => 'nav_links', 'theme_location' => 'nav_links', 'container_class' => 'nav-links clearfix', 'fallback_cb' => 'nav_links_fallback' ) ); }
If you created a menu, you would have to drag in those pages, as the basic `Walker_Nav_Menu` class does not pull subchildren into it. If this is your desired effect, you could created a custom Walker, essentially duplicate the `start_el()` function of `Walker_Nav_Menu`, and perform a check on `$item->type` to see if you are dealing with a Category - then create your submenu manually.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus" }
Query Vars Not Set in Main Query I have a function that checks page specific and global settings to determine a class related to sidebars. I call the function from the archive.php template and try to check that `post_type` is 'post', however the `post_type` var isn't set. Relevant Code: function get_sidebar_class() { global $wp_query; echo 'Post type: ' . get_query_var( 'post_type' ); echo '<pre>' . print_r( $wp_query->query_vars, true ) . '</pre>'; } `post_type` comes back empty for both attempts. Why isn't it set? Other variables (E.g. `category`) are set, but not `post_type`.
Query vars are... fun like that. Depending on which archive you are messing with `get_post_type()` just might be simple enough to do it (it gets type from actual post, not query). Otherwise you might want to go for `get_queried_object()` to figure out what precisely you are dealing with.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp query, query variable" }
Let plugin check if taxonomy is already registered by another plugin My site is using a custom taxonomy that can be associated with two different custom post types. Each post type is registered by a different plugin. It may be that only one of the plugins is active or that both are activated. My idea was to let each plugin check if the taxonomy has already been registered and —if not— register it. I put the following code into each plugin, but this —of course— gives me an error (Cannot redeclare register_taxonomy_my_taxonomy). if ( !taxonomy_exists( 'my_taxonomy' ) ) { add_action( 'init', 'register_taxonomy_my_taxonomy' ); function register_taxonomy_my_taxonomy() { ... }
The problem is that the function is defined whether you use it or not. What you want is the PHP function `function_exists` if ( !taxonomy_exists( 'my_taxonomy' ) && !function_exists('register_taxonomy_my_taxonomy') ) { add_action( 'init', 'register_taxonomy_my_taxonomy' ); function register_taxonomy_my_taxonomy() { ... } You should be able to create a reusable library (class) that would take care of this problem more elegantly, though.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, custom taxonomy" }
How do I add to the list table a filter? I am trying to find the hook for adding a filter to the list under "Posts [Add New]": !enter image description here
You can use `views_edit-post` hook to do so. It is a possible variation of `views_{$this->screen->id}` and resides in class-wp-list-table.php. add_filter('views_edit-post', 'my_post_views' ); function my_post_views( $views ){ $views['html_class_name_for_li'] = 'the html'; // ex: <a href="#">something (11)</a> return $views; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "plugins, wp admin" }
linking to post outside the loop Is there an easy way to link to a specific page/post outside the loop? I used the `get_permalink()` code as follows. <a href="<?php echo get_permalink( 164 ); ?>/post-slug/"> </a> But this meant that I had to get the post ID from the Shortlink in the Admin for the post I wanted and then append the slug to it. Is there a better way to get the post ID of the post I am looking for, without using the loop? My permalinks are set up to use the post name so this seemed to work.
Have you tried the `get_page_by_title` function? You can use like `<?php echo get_permalink(get_page_by_title('My Post Title')); ?>`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, loop, id, shortlink" }
Show all videos by tag name I need to get all videos by tag name, im using code like that $tax_terms = get_terms('media_category', 'orderby=count&order=DESC&hide_empty=0'); foreach ( $tax_terms as $tax_term ) { $posts = get_posts(array( "meta_key" => 'select', "meta_value" => 1, "post_mime_type" => "video", "taxonomy" => $tax_term->taxonomy, "term" => $tax_term->slug, "numberposts" => 100, "posts_per_page" => 100)); ?> But that query dont returns any elements, what's the problem is?
Try this. Use for tag_id in get_posts. $tax_terms = get_terms('media_category', 'orderby=count&order=DESC&hide_empty=0'); foreach ( $tax_terms as $tax_term ) { $posts = get_posts(array( "meta_key" => 'select', "meta_value" => 1, "tag_id" => 5, "post_mime_type" => "video", "taxonomy" => $tax_term->taxonomy, "term" => $tax_term->slug, "numberposts" => 100, "posts_per_page" => 100));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tags, get posts, terms" }
wordpress plugin license issue -New plugin development Can i copy all the codes of a free plugin and paste it in my new plugin ?. Is there any license issue for using the others plugin code. My new plugin is working properly ,but for making this plugin i copy the resources of other free plugin .
You have to find out how the plugin is licensed that you are going to use. Then read the details of that licence. Usually the least to do is to mention the author and/or name of the plugin used. For reference WordPress is licensed under GPLv2 (or later). * The WordPress License
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, php" }
Super simple shortcode not working Have been looking at various tutorials and answers here and elsewhere and just can't get this to work. Just trying to display a simple output from a shortcode as below, but it is just outputting the actual shortcode tag to the page instead of the content from the shortcode **Functions.php** <?php function welcome_roundels_func(){ return "testing"; } add_shortcode( 'welcome_roundels', 'welcome_roundels_func' ); ?> add_action( 'init', 'register_shortcodes'); **Usage** [welcome_roundels] Is there anything else I have to do to enable shortcodes, or should the above work? **Edit** I am also using the below code to output the content $welcomePage = get_post( 5 ); echo $welcomePage -> post_content;
Your problem is here: $welcomePage = get_post( 5 ); echo $welcomePage -> post_content; Shortcodes are processed on display by via a filter on `the_content` which is called by the function `the_content()`. You've bypassed that functionality and are `echo`ing the raw post data. You need to output your code using a proper Loop or explicitly process the shortcode. echo do_shortcode($welcomePage -> post_content);
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "functions, filters, shortcode" }
Restore Category Base One hiccup I've noticed with WordPress is that when you use any plugin which removes the category base for posts and turn the plugin off, your posts will now return 404 errors. In addition, WP will continue to remove the category base - even though the plugin is deactivated. Thus far, I've tested this with two plugins with the same result: < < Is there a way to fix this?
This question was most likely down voted because the answer is in the plugin support forum. As stated by others in the comments, set default permalinks and save settings. Clear cache. Set permalink structure to what you want and save. Also, feel free to look in the database. where is permalink info stored in database?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, errors" }
Preferred way to include Advanced Custom Fields in a plugin? So I am building a plugin for a site that is already using Advanced Custom Fields (ACF). I wonder what would be the best way to include ACF in my plugin? The site is already using ACF, so is it possible to include ACF from the plugin directory or should I include ACF again?
If ACF (or any other plugin) is active on the site you do not need to include its files as they are all being included in the wordpress initialization process. The only tricky part is that you don't know the order in which files are included and yours might be included before the ACF files are included, therefor you should probably wait for the `init` action or even later action before using it. Side note: ACF provides GUI for custom fields, but if you just need to use the data it is better not to rely on its API and query using the `get_post_meta` API. This will result in better software modularization and hopefully a more maintainable site.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "plugin development, advanced custom fields" }
Always show same size tags for Tag Cloud in Wordpress Admin I wanted to know if there was a way to modify the back-end of Wordpress to do 2 things: * Make all tags' font the same size, so none are larger than the others * Always show the most used tags when creating/editing a post This only applies to the back-end of Wordpress, not calling the tag cloud or any sort of front-end CSS that would be found in the theme.
use this at functions.php /* Tagcloud, change the font size */ function custom_tag_cloud_widget($args) { $args['largest'] = 13; //largest tag $args['smallest'] = 13; //smallest tag $args['unit'] = 'px'; //tag font unit return $args; } add_filter( 'widget_tag_cloud_args', 'custom_tag_cloud_widget' );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "wp admin, tags" }
is there a way to get all queued scripts/styles into a template without `get_header()`? in my main plugin page i check if a certain page is visited if so, i load a certain template. in the following way: add_filter( 'template_include', array($this, 'includeTemplate'), 99 ); public function includeTemplate($template){ global $wp_query; if(is_page() && $wp_query->query['pagename'] == 'my_page_name'){ include(plugin_dir_path( __FILE__ ).'templates/my_page_name.php'); die; } return $template; } my question is how can i load all the queue scripts and styles to this template without using `the_header()` I've tried : global $wp_scripts; foreach( $wp_scripts->queue as $handle ) : echo $handle . ' | '; endforeach; The above echoed `admin-bar` Thanks.
`the_header()` does not even seem to be native WP function? Technically getting header isn't what really causes styles and scripts to load, it's `wp_head()` call that should be made there (and `wp_footer()` call in footer). So they are likely what you should be using. If you do need something lower level you might want to look at: * `wp_print_styles()` * `wp_print_head_scripts()` * `wp_print_footer_scripts()`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp enqueue script, wp enqueue style, scripts, css" }
Why is my subdomain returning a 403 status? I have a Wordpress installation at www.mysite.com. Wordpress is installed in `/public_html/` I created a sub domain test.mysite.com. cPanel asks for the directory in my file system. I pointed it to `/public_html/wp-content/themes/mytheme/test/`. When I do this, I get a 403 error. When I point it to `/public_html/`, it works - displays main page of my website. How do I get test.mysite.com to show what I have in `/public_html/wp-content/themes/mytheme/test/`
There are some questions I have but cannot add a comment so will do my best to help clarify the steps to set up a subdomain network: < First, the multisite feature of WordPress needs to be enabled. Did you do the steps required to enable multisite? Second, the same wordpress files are used for the main site and any network enabled site. In other words, if you have public_html/wordpress for the domain.com then in cpanel you also point the subdomain to public_html/wordpress for a sub.domain.com. You do not create a directory public_html/wordpress/sub. The directory does not exist but the multisite feature enabled will recognize to render the WP files when sub.domain.com is requested in the browser.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "subdomains" }
WP-CLI works on non WP-CLI installed Wordpress instance? I came across WP-CLI via the tutorial at < and was wondering does WP-CLI work on Wordpress instances which were NOT initially installed with WP-CLI but installed via normal FTP upload Wordpress installs ? So can I manage plugins, core updates via WP-CLI on non WP-CLI installed Wordpress installs ?
Yes, of course it does, as long as you also have SSH access to the instance (it won't work over FTP). There's nothing special about WordPress instances installed via WP-CLI. Commands such as `wp core download` and `wp core install` perform the same actions you would normally do when installing manually.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "wp cli" }
List custom taxonomies associated to an author's posts On the author template, I would like to display a list of the custom taxonomies associated to the posts written by that author. In details: I have a "clubs" taxonomy, which is non-hierarchical and applies to Posts. On the author template, I need to display a list of the "clubs" used by that author's Posts, as links. In this manner, i can list the clubs to which this author participates in. Is that possible?
First grab the post ids by the author, and then the terms. $author_id = '1234'; $taxonomy = 'clubs'; $post_ids = get_posts('fields=ids&post_type=post&post_status=publish&showposts=-1&author='. $author_id ); $clubs = wp_get_object_terms($post_ids, array($taxonomy)); $html = '<ul>'; foreach( $clubs as $club ) { $html .= sprintf( '<li><a href="%1$s">%2$s</a></li>', get_term_link($club, $taxonomy), $club->name ); } $html .= '</ul>'; echo $html;
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, author" }
Starting from what version WordPress provides own embedded audio player without need a plugin? According to **THIS PAGE** Wordpress now provides own embedded audio player. Does anyone know starting from what version this became available?
Wordpress 3.6. Wordpress also features a video player as well, so no need for plugins anymore * Audio / Video support in Core
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "audio" }
How to display only introtext? For development of my custom template, I need to show only a intro text of some posts. Can you help me how to achieve that? More informations: As we all know, single WP post is defined as: This is post's introducion text <!--more--> Main post content, blah blah blah All I need is somehow to display > This is post's introducion text ... on frontend.
While I am sure that the logic of what I am about to post is too simple, I think it should get you started. Your terminology is odd but what it seems you want is to display the "post before the more" part of the post body. To do that, you need to break the post content into "post before the more" and "post after the more". There is a function for that. $pieces = get_extended($post->post_content); // var_dump($pieces); // debug echo apply_filters('the_content',$pieces['main']); Inside a Loop, that should work just fine. In other contexts you may need something other than `$post->post_content`. Excerpts, manually or automatically created, will not come into play so you may need to include that in the logic.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "posts" }
How can I include a file related to blog URL? Nothing seems to work When I was building my website locally using WAMP, I was just using simple include '/extras/file.php'; Of course, that would start at the root folder, and look in the extras folder. However, now I'm putting the website on a webserver, and have put it in a subdomain (to not interfere with the current live site). So I tried to change the include tags to a few different variations: include (home_url().'/extras/file.php'); include home_url().'/extras/file.php'; - (without parent brackets) And also the two variations above, but using bloginfo(url), get_bloginfo(url) etc but still nothing seems to actually output anything. Could it possible be becuase of the subdomain? If I alter the include statement, I can sometimes echo the home url as text, but that's not what I want. Am I doing it right? or is there something obviously wrong?
The URL is the public web address. It is not related to the local file system. So what you need it a reference to the file system, not to the URL. // path in relation to document root include $_SERVER['DOCUMENT_ROOT'] . '/extras/file.php'; Or // path in relation to current position include dirname( __FILE__ ) . '/extras/file.php';
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, include, home url, bloginfo, references" }
What is good W3 total database caching option? I have a centOS VPS (Apach+Nginx). Right now I use APC for w3 total plugin cache (disk enhanced for page cache). I have less than 25MB database. I can see several w3tc, APC cache errors. I think the main issue is Zend optimizer. What is the good option for wordperss database cache (eAccelerator, XCache)? Error. PHP Strict Standards: Declaration of W3_Cache_Apc::delete() should be compatible with W3_Cache_Base::delete($key, $group = '') in /home/xxxxx/public_html/wp-content/plugins/w3-total-cache/lib/W3/Cache/Apc.php on line 189
For database caching you should try Memcached instead, in PHP 5.5, APC for W3 Total Cache will not work like for 5.4 or 5.3.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "database, plugin w3 total cache" }
Administrator role capabilities I need to make that administrator could'nt manage options, but it is not working... My code: function set_capabilities() { $editor = get_role( 'administrator' ); $editor = remove_cap('manage_options'); } add_action( 'admin_init', 'set_capabilities' ); What I do wrong ?
you're creating a function and just initializing a local scope variable that you overwrite it. here is a different approach: global $wp_roles; // global class wp-includes/capabilities.php $wp_roles->remove_cap( 'administrator', 'manage_options' ); _based on codex:remove_cap_ Edit: /** * Remove capability from admins. */ function wpcodex_set_capabilities() { // Get the role object. $admin = get_role( 'administrator' ); $admin->remove_cap( 'manage_options' ); } add_action( 'init', 'wpcodex_set_capabilities' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "capabilities" }
Linking Plugin Files to WP I am writing a plug-in right now which adds a table to the database when activated. I have another file in my plug-in directory which handles a form submission and writes to the database. This file seems to have no link to WP, because it returns NULL when I ask for the **global $wpdb** <?php header('Content-type: '.$_POST["mime-type"].''); header('Content-Disposition: attachment; filename='.$_POST["filename"].''); global $wpdb; $table_name = $wpdb->prefix . "my_plugin"; $rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql') ) ); readfile($_POST["file"]); exit; ?> If I were to make this a custom template file for some private page and then submit forms to that page I think it would work. But I know there must be a way to do this all within the plug-in directory. ### Plug-in Code
You need to include the "capability" to use `$wpdb` in your page. Include this in your page and see what happens. <?php $path = $_SERVER['DOCUMENT_ROOT']; include_once $path . '/wp-load.php';
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, forms, mysql" }
include script that depends on modernizr? first time i am trying to include script to wordpress,but after several hours reading wordpress codex and answers all over the web ,i still dont success to link the script to modernizr, they both show in the head of the page as if they were registerd correctly but the script still ignores modernizr. here is the code in function.php function childtheme_script_manager() { wp_register_script('new_service', get_template_directory_uri() .'/js/modernizr.custom.79639.js', array('jquery'), true, true); wp_enqueue_script('new_service'); } add_action('wp_enqueue_scripts', 'childtheme_script_manager'); function twentyfourteen_child_scripts() { wp_enqueue_script('twentyfourteen_child_scripts', get_template_directory_uri().'/js/jquery.swatchbook.js'); } add_action( 'wp_enqueue_scripts', 'twentyfourteen_child_scripts' );
I assume these are child theme scripts because of your function name: twentyfourteen_child_scripts() When loading scripts from your child themes functions file you should use: wp_enqueue_script( '$handle', get_bloginfo( 'stylesheet_directory' ) . '/js/filename.js', array( 'jquery' ), '1.0.0' ); Or use add_action( 'wp_enqueue_scripts', 'child_add_modernizr_scripts' ); function child_add_modernizr_scripts() { wp_register_script('modernizr', get_stylesheet_directory_uri() . '/js/modernizr.js', false, '1.0', true ); wp_enqueue_script( 'modernizr' ); } Another potential problem maybe the file names are invalid for some reason. get_template_directory_uri() Applies to parent themes.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "wp register script" }
wp_nav_menu not highlighting the current category when viewing a single post My WordPress site has a bunch of posts, all filed by a top-level category and a bunch of subcategories therein. I have the main site nav rendering the category pages, which, when clicked, get all posts in that top-level category as an 'archive'. The category highlights as you'd expect when you visit one of these category pages, however, when visiting a single post in this category, no highlighting for me. I'd expect that the top-level category to which this post belongs would be highlighted and it looks as if that is the intended behaviour. So, my question is: What can I do to make the category the post belongs to highlight in the main nav when I'm viewing a single post? The site gets quite a lot of traffic so I am keen to get a solution that scales well.
There are several built-in CSS classes that come with the `wp_nav_menu`. In your case, you are looking for something like a _current category_ class, which is **not** included. But we can easily add that to the CSS classes: function wpse_134409_current_category_class($classes, $item) { if ( is_single() && 'category' === $item->object && in_array($item->object_id, wp_get_post_categories($GLOBALS['post']->ID)) ) $classes[] = 'current-category'; return $classes; } // function wpse_134409_current_category_class add_filter('nav_menu_css_class', 'wpse_134409_current_category_class', 10, 2); **Please note** : this code is untested! Now you can target your menu item like so: #menu-id li.current-category { /* styles */ }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "categories, menus, navigation" }
How do I make pagination_links show as 01 02 03, instead of 1 2 3? Based on: < how to make these links show as 01, 02, 03... rather than the normal single digit? thanks so much
Try switching the pagination type to array. That way you can use each link in a loop and add what you need to them: Using the example from the codex: global $wp_query; $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages, 'type' => array ) ); foreach ( $paginate_links as $link ) { echo sprintf("%02s", $link); } The php sprintf function will add a leading zero.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pagination" }
How to pass data parameter to ajax action function handler I have the following js to process an ajax request: $('#someelement').click(function() { var cokeValue = 'coke'; var data = { action: 'load_post', another_par: someVar }; jQuery.post(ajax_object.ajax_url, data, function(response) { alert(response); }); }); And this is my ajax handler function (hopefully my terminology is correct): add_action('wp_ajax_get_coke', 'get_coke_ajax'); function get_coke_ajax() { // need to get another_par in here !!!!!!! die(); } As you can see, the action is `load_post` which is fine, but I need to pass the `another_par` parameter to my ajax function so that I can assign its value to a variable and use it for my purposes.
When you use `jQuery.post()`, the `data` is sent as regular `$_POST` arguments. So this JavaScript … var data = { action: 'load_post', foo: 'bar' }; … is available in your callback function per: $action = $_POST['action']; $foo = $_POST['foo']; // bar And when you are using `jQuery.get()`, the data is in `$_GET`. You can also use `$_REQUEST` which returns both, `GET` and `POST` data (and `COOKIE`). But you should always ask for the specific resource to avoid injection from sources you didn’t expect, like a cookie.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 8, "tags": "ajax" }
woocommerce_order_status_completed action hook not working I am developing woocommerce extension wher i need to perform some task after order is successfully completed. For that I started coding. I used following code in constructor of my class. add_action(‘woocommerce_order_status_completed’,array(&$this,’insert_points’)); Then I defined function as follows: public function insert_points($order_id) { global $woocommerce, $table_prefix; $order = new WC_Order($order_id); var_dump($order); } But it is not working. Can anybody please help me using code sample.
May be try this add_action(‘woocommerce_order_status_completed’,array(&$this,’insert_points’),10,1); add_action hooks has last argument which specifies how many arguments to pass to function in hook.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, woocommerce offtopic" }
Is it necessary to use a WordPress nonce when allowing users to download public data? I am using jQuery `.load()` to load the next page of WordPress posts after a button is clicked. The next page of posts is public data (no access restrictions on it whatsoever). Should I use a WordPress nonce check in this situation? If so, then please explain why. Thanks in advance.
Nonces are used to verify that a request is allowed from the sender. For public data, all GET requests are allowed, if they match existing public content. So no, do not use a nonce for that. You have nothing to do if the nonce validation fails. That’s always a good indicator for unnecessary information.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, security, nonce" }
How to ensure "the_content" filter runs only for the main displayed content? I have a plugin which adds the method to "the_content" filter. `add_filter('the_content', 'myFilteringFunction', 10000);` Within that function I want to add some links on the beginning and the end of the content. But I only need to do it for the "main" content of the displayed page so - not in the any of the widgets, not in the footer, header etc. Moreover I only want it to be included for the custom post type which I defined in the same plugin. So I figured out that kind of check, thinking it would be enough. if( is_single() && get_query_var('post_type') == 'myCustomPostType' && is_main_query() ) Unfortunately it's not working as intended - at least not in every case. On the page the plugin WP Types is installed, it's not working (the links are added despite the condition). Why?
Try adding a condition to your filtering function that checks your post type against get_post_type. `if ( 'book' == get_post_type() )` If you wish to apply this filter to pages as well, try is_singular() and include your custom post type(s) as an argument. `is_singular('book');` This will return true if any of the following conditions are true: is_single() is_page() is_attachment() 'book' == get_post_type()
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "plugin development, wp query, the content" }
Wordpress Comment Box on woocommerce product page can we activate same comment widget on woo-commerce product page which WordPress gives on post or pages. actually i want other users should be able to comment on others comment which is not allowed in review.
Replies aren't disabled for reviews in woocommerce, but there is no output of a reply button. If you add one to the `review.php` template via `comment_reply_link()` \- exemplary usage below - replies are possible. **Code:** $args = array( 'reply_text' => 'Reply <span>&darr;</span>', 'depth' => '1', 'max_depth' => '5' ); comment_reply_link( $args );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "woocommerce offtopic" }
Where to place landing pages or files inside wordpress? We have some content that it's outside the wordpress instalation like landing pages, or forms which sometimes must be embedded. I'm wondering where to place them so I don't loose it if I update the wordpress installation or change the theme. I thought about placing it on the wp-content folder, is it a good idea? If not where should I place them?
Put them either in an individual folder **next to** `/wp-content` etc., or put the folder **inside** `/wp-content`. You won't lose the files either way. Core updates take place in `/wp-admin` and/or `/wp-includes` only.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "content" }
Solution for database version control and deployment? Currently i use a dump script and commit the database to the git repo. `--skip-extended-insert --skip-comments --skip-dump-date` means that a diff can give me a fair idea of what has changed, but it all falls down if I try to merge. The WP_SITEURL, WP_HOME and all the other places wordpress stores full URLs need updating when importing to another host (testing,staging,production) Is anyone using a better method? **Main issues:** * Wordpress stores full URLs all through the database (non-portable) * Lots of other, non-relevant records change * auto_increment values (i just strip these out, but have run into ID issues) * timestamps (can also strip out, potentially) * _transient_ * records ... no idea what to do with them A process that created timestamped migrations, with only the things added or removed, would be ideal... but i'm not sure if it's even possible?
Here are two possible solutions, both of these are actually generic MySQL version control tools but can be adapted to your workflow: dbv.php This tool creates "migrations", which are basically SQL scripts, from the changes detected on the database. These scripts are stored in a local directory and thus can be commited to your current VCS (git, for example). It's used through a PHP web interface. DBVC Fundamentally similar to the previous tool, this is based on a command line interface. It's configured through a json file. The main difference is that it doesn't auto-generate the migration files. There's a pending issue to integrate this with the previous similar, so that's something to look for. **Wordpress Plugins** Some plugins that could aid in the creation of a repeatable workflow: * VersionPress (still in early development at this date) * WP Migrate DB (there is a pro version) * WP Synch DB (a fork of the previous project with some of the pro features included)
stackexchange-wordpress
{ "answer_score": 5, "question_score": 12, "tags": "database, migration, version control" }
Wordpress or plugin need tomcat? I have a managed VPS. It's a CentOS 6.4 + Apache 2.2 + Nginx admin 4.4. When I'm running **top** process in SSH, I can see there's a tomcat process (uses 1.9% RAM). This VPS has only wordpress sites. I want to know Wordpress or its plugin need the tomcat to run? How do I check if a plugin need tomcat? PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 24085 tomcat 20 0 657m 50m 8728 S 0.0 2.0 0:02.57 jsvc
WordPress does not need Tomcat. All WordPress needs is... > To run WordPress your host just needs a couple of things: > > * PHP version 5.2.4 or greater > * MySQL version 5.0 or greater > > > < Plus adequate RAM-- 32MB for a single site, 64MB for Multisite. Many hosts these days provide much, much more than that by default. I don't know if there are plugins (or themes) that do, but certainly you can check the Docs for _your_ plugins and find out if any of those need it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "server" }
Taxonomy Parent not showing up in address bar I created a custom taxonomy successfully and assigned the custom post type as well. It is a hierarchical taxonomy and I added terms in the back in a hierarchical way. I added for instance main Category "MAIN" and sub category "Sub Cat". Now, when I go to look at "Sub cat" in the from end, I get `/mysite.com/THE-CHOSEN-SLUG/sub-cat` instead of `/mysite.com/THE-CHOSEN-SLUG/main/sub-cat` What am I missing? I have worked with CPT and custom taxonomies for a while already and am very versed in wordpress. Anything changed lately?
I found an answer within 10 minutes of posting this. :) Just add `'hierarchical' => true` in the `rewrite=>array()` of the taxonomy as follows: $args = array( ... 'hierarchical' => true, 'rewrite' => array( 'slug' => 'THE-CHOSEN-SLUG', 'hierarchical' => true, ), ); register_taxonomy( 'my-custom-taxonomy', array( 'page', 'my-custom-post-type' ), $args ); Then flush the rewrite rules by going to the Permalink settings and saving them, and voila!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "templates, url rewriting" }
Odd spacing in Navigation Bar I am in the process of redesigning my website, and i'm struggling to find what is causing spacing (margins i'm assuming) between navigation items. I have been delving through chrome developer tools and I cannot find what is causing it anywhere. Note that when you hover between items there is a noticeable white bar between items.
That issues is often encountered when using inline-block on elements. Could be fixed with a good CSS reset when starting the theme (may force you to rewrite lots of css sections) or by making the menu "li" elements display block and float left instead. Check my screenshot how I "fixed" your problem. !enter image description here image link
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus, css, navigation" }
My posts section for logged in user I would like to create a page that shows only posts written by the user logged in and get a link (such as www.example.com/AuthorPostsID) to put on the menu. I'm trying for two days. Does anyone know how to fix it? Thanks EDIT: I tried using the following code, putting it in the function.php file, but I do not know how to proceed: if ( is_user_logged_in() ): global $current_user; get_currentuserinfo(); $author_query = array('posts_per_page' => '-1','author' => $current_user->ID); $author_posts = new WP_Query($author_query); while($author_posts->have_posts()) : $author_posts->the_post(); ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php endwhile; else : echo "not logged in"; endif;
You don't need to put your code in your theme functions. This needs to be a custom page template. Learn about page templates here: < Your code is custom loop so you need to also learn about loops and then using WP_Query so next stop will be here: < Then read this page: < After you do this you will be ready to implement your custom loop to show authors their posts. Study, the codex so that you have a better understanding of how WordPress works before you make changes to things that will break WordPress. Then when you ask questions here you will be able to get a better answer to problems that you are having because the people here will understand your question better.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, permalinks, users, archives, links" }
Assign multiple roles , overlapping capabilities What happens if i assign let's say 2 different (custom) roles to a user that both of which have the same (custom) capability?
I am pretty sure that nothing would happen other than the user would have the capability in question. Think about it. The default Roles share many capabilities\-- Authors, Editors, and Administrators all have `edit_posts`, for example. All roles (usually) have `read` The same system manages both default and custom roles/capabilities, so there really should be no problem.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "capabilities, user roles" }
Excluding cateory not working on my site. how to solve this? I am using my own wordpress theme. I am trying to exclude some categories on my `author.php` I am using the following code for that purpose. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $author_id=$post->post_author; $args = array('author'=> $author_id, 'posts_per_page' => 10, 'paged' => $paged, 'category__not_in' => 16, 19, 1, 20); query_posts( $args); ?> I tried `$args = array('author'=> $author_id, 'posts_per_page' => 10, 'paged' => $paged, 'cat' => -16, -19, -1, -20);` also not working. How can I exclude those four categories.
You need to wrap your ids in an array. $args = array('author'=> $author_id, 'posts_per_page' => 10, 'paged' => $paged, 'category__not_in' => array( 16, 19, 1, 20 ) ); <
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "categories, exclude" }
Admin Panel - Custom Menu Sub-Item LINK I'm trying to add a custom link under my Post Type in my admin menu, which will link to Pending Posts. This code functions, but it instead makes a page (like I suppose the function should), but I just need a single link and there doens't seem to be a `add_submenu_link` function unfortunately. Is there a way to create a static link but place it in my post type submenu? /** Add Pending Posts to WP Admin Menu **/ function add_custom_link() { add_submenu_page('edit.php?post_type=cpt_custom', '', 'Pending Posts', 5, __FILE__, 'sub_page_pending'); } function sub_page_pending() { echo '<li><a href="edit.php?post_status=pending&post_type=cpt_custom">Pending Posts</a></li>'; } add_action('admin_menu', 'add_custom_link'); I've tried to use a `wp_redirect()` but I get some errors telling me that the headers have already been set.
Insert the URL of the page as the `$menu_slug` argument. Also note that user levels are deprecated, you should pass a capability instead. function add_custom_link() { add_submenu_page( 'edit.php?post_type=cpt_custom', '', 'Pending Posts', 'edit_posts', 'edit.php?post_type=cpt_custom&post_status=pending', '' ); } add_action('admin_menu', 'add_custom_link');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "customization, wp admin, admin menu, sub menu, add submenu page" }
Website Preview Graphic for Wordpress Site No idea how to ask this... so I'll give it my best. I have a Wordpress site, self hosted. When I post a link to a post on Facebook, Facebook tries to detect a preview graphic to show along with the post (see screenshot) !Example For whatever reason, Facebook always picks up the Stumbleupon share button for the graphic. It's not the first graphic on the page, and it's not the last either, so I'm not sure why. But more importantly, my question is... when I am not using a Featured Image for the post (sometimes I do, sometimes I do not), how can I make sure that previews such as this pick a different image? The site uses a favicon, but that doesn't seem to work in this instance. Is there an image, or something I can set in code, that would allow me to specify what image gets picked up when a site tried to create a preview like this?
The accepted answer over on StackOverflow looks to be the best way to do this. You'll want to get into your header.php file to make these changes. < Now if the image should change from post to post, I would probably write something using JQUERY to change the value of the meta tag on the post.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "facebook, open graph" }
How to add menu to Dashboard that can be viewed by all users I am able to add Menu to the Dashboard using the below code, it can be viewed by an administrator. That menu doesn't appear when logged in as an Author or a Subscriber. How to make sure every user can view the custom added menus. //Add Menu Page add_action( 'admin_menu', 'register_my_custom_menu_page' ); function register_my_custom_menu_page(){ add_dashboard_page( 'custom menu title', 'Test', 'manage_options', 'custompage', 'my_custom_menu_page', plugins_url( 'test/images/icon.png' ), 6 ); } function my_custom_menu_page(){ echo '<div class="wrap"><div id="icon-tools" class="icon32"></div>'; echo '<h2>Test</h2>'; echo 'Test'; echo '</div>'; }
You have to use the right capability for this. You chose `manage_options`, which by default only users with an Administrator user role have. So, change it to `read` or `exist`, for instance, and **every** user will be able to see and access the menu. add_dashboard_page( 'custom menu title', 'Test', 'read', 'custompage', 'my_custom_menu_page', plugins_url( 'test/images/icon.png' ), 6 );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "menus, admin, dashboard" }
Add unique id to Preview URL Is there an easy way to append a unique ID to the preview URL when the preview button is clicked by a user? So this: < Becomes: I ask because our setup caches heavily on the server-side so when updating it takes a while for the changes to show up in the preview. Manually adding a parameter to the end of the URL allows the changes to show up immediately. I tried searching for a plugin but didn't have any luck. Is there a way to do this by adding a custom function in functions.php?
Use the `preview_post_link` filter to modify the preview URL: function wpa_preview_link( $preview_link ){ return $preview_link . '&v=' . uniqid(); } add_filter( 'preview_post_link', 'wpa_preview_link' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, urls, cache, previews" }
disable lightbox in a plugin i'm using the PHOTO ALBUM plugin for wordpress and I would like to disable the lighbox effects - meaning, i just want to show the thumbnails... is that even possible? Thank!
You just need to determine the handle of the script that they are enqueueing, and you can dequeue it yourself and prevent it from being loaded. I downloaded the plugin and had a look, my guess is (I haven't tested) that the lightbox script is jquery.fullscreen-0.4.1.js, which gets loaded on line 2448 of photo-gallery.php function my_lightbox_prevention() { wp_dequeue_script( 'jquery-fullscreen' ); wp_deregister_script( 'jquery-fullscreen' ); } add_action( 'wp_print_scripts', 'my_lightbox_prevention', 100 ); Add that to functions.php and it should do the trick. You might have to dequeue a couple other scripts as well but this should point you in the right direction at the very least.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, customization, css, theme customizer" }
Is there a way to prevent a function/method from being called outside a specific hook? I would like to make function only callable by a specific action, in this case the `register_activation_hook()` function. How can I do this?
There's a Wordpress function current_filter() that retrieves the name of the current filter or hook that called a function/method. You can match it to a whitelist and either end or continue the function based on the result.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, hooks, actions" }
Proper use of option_page_capability_{$page_name} I am having trouble giving access to an options page to Editors. I am pretty sure I need to use the filter `option_page_capability_{$page_name}` but it is not working for me. Is there a specific place to hook this? I am still getting the `Cheatin', uh?` error with this: function bf_ins_capability(){ return 'edit_posts'; } add_filter( 'option_page_capability_brightfire-insurance-settings', 'bf_ins_capability' );
So in this hook is not exactly looking for the `{$page_name}`. Once I replaced the `{$page_name}` part of this filter to the `{$option_group}` parameter from my `register_settings()` function, all is well in the land of WordPress. Here is what my update needed to look like. function bf_ins_capability(){ return 'edit_posts'; } add_filter( 'option_page_capability_bf_insurance_settings', 'bf_ins_capability');
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "options, capabilities" }
Add links widget to self-hosted blog? < discusses a Links widget that makes it easy to create a blogroll in your sidebar. I'm not seeing this widget in my blog by default, and searching the plugins available is not turning it up. Is this feature available to self-hosted blogs? How, if so? Or is this one of those features only available to wordpress.com sites and I'll just have to find another similar widget?
Links were removed from standard Wordpress in 3.5 I believe. To add them, use the Links Manager plugin - I believe this will enable the Links widget as well.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets" }
Wordpress - Image href for home menu nav not working I have an image linked to a li element from a navbar in wordpress. All is working fine but when i hover mouse on image, it also shows a menu element hover in the list. How can i hide that when it is linked to the image? This is the php code for that (from nav-menu-template.php): if( $args->theme_location == 'primary' ) return "<li id='menu-item-1000' class='menu-item menu-item-type-post_type menu-item-object-page menu-item-1000'><a class='logo' href=' style='position:absolute;top:-20px;left:-125px;z-index:200;max-width: 402%; ' src=' alt='Exelo' ></a></li>".$items; I attach an image to show what it is doing: !enter image description here
The class used for your navigation menu's anchor tag has a css selector `:hover`. Because the image logo has been added withing the anchor tag, it is considered a part of the link and the hover styling affects it as if it were any other link in your nav menu. ## Solutions * Find another way to add the logo image to your site. * Use a different class for this particular anchor tag that is used by the rest of the navigation menu. * Add a unique class to this anchor tag and reset the styling for the `:hover` selector. The most visible styling here is probably the `backgound-color` property, but refer to your nav menu's `:hover` styling to determine the properties being used.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, css, html" }
wp_insert_post not working for custom post type? For whatever reason `wp_insert_post` doesn't work for a custom post type. Here's the code snippet I'm using. $new_post = array( 'post_type' => 'rsp_synonym', 'post_title' => wp_strip_all_tags( $row['word'] ), 'post_date' => date('Y-m-d H:i:s'), 'post_author' => 2, 'post_content' => '', 'post_status' => 'publish', 'comment_status' => 'open', 'ping_status' => 'open' ); $post_id = wp_insert_post( $new_post ); if (is_wp_error($post_id)) { $errors = $post_id->get_error_messages(); foreach ($errors as $error) { echo "- " . $error . "<br />"; } } Strange enough, it doesn't even return a WP_Error using the `if (is_wp_error($post_id))` conditional. But still, no posts are being added. The custom post type named as `rsp_synonym` has been registered before using this call.
Try add the second parameter like: $post_id = wp_insert_post( $new_post, true ); If it still won't work, please var_dump the $post_id and paste here.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, api, wp insert post" }
Localize variables with TinyMCE script I am writing a plugin that has variables that I would like to localize for use within TinyMCE. The logical choice seemed to me to localise them with the enqueued TinyMCE script itself like so: public function localize_variables() { wp_localize_script( 'tinymce', 'varName', 'value' ); } add_action( 'admin_enqueue_scripts', 'localize_variables' ); However I can't find where TinyMCE is being enqueued! I put this little function at the bottom of my functions page and ran it on my Admin edit posts page: function my_inspect_scripts() { global $wp_scripts; print_r($wp_scripts); } add_action( 'wp_print_scripts', 'my_inspect_scripts' ); After going through the data dump I noticed that TinyMCE was not in the list of scripts being enqueued! However the script its self was being loaded as a resource within the browser. I feel like I am missing something here.
Looks as though Tiny MCE is not enqueued. Looks like it is loaded through the _WP_Editors class in class-wp-editor.php. There is a action hook in there called `before_wp_tiny_mce` where you can output a script with some localised variables... This is what I am going to do.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "tinymce, wp localize script" }
Plugin data shared in Multisite I am trying to build a site that very closely resembles another and so far so good with WordPress Multisite Networks. I am also using the plugin WP-FileBase - this plugin creates a database table per site (< - is there any way for me to set it up so that the sites share the same database?
You are asking a question that is specific to a plugin and not WordPress. How the plugin functions depends entirely on the plugin author's design. Reading the article above, sure the plugin works in WP multsite, but as the author mentions extra works needs to be done to share that content among other mulisite sites. You should follow up on the plugin support forum for answers.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, database, mysql" }
Upgrading from 3.4.2 I recently took on a new client who runs a fairly active news site powered by WordPress. Part of what he wishes me to do is upgrade his WordPress version, something he's neglected to do since 3.4.2, my question is now: Would it be feasible to upgrade to 3.8.1 straight away or should I opt for taking it in small steps (start by upgrading to 3.5, then 3.6 etc.)? What would be appropriate security measures to take to prevent loss of data when doing this? I reckon problems will arise with the active plugins and his current theme so will I need to do a full backup of all files a database dump or will less suffice? Thanks in advance
I would make a backup and put it on a dev URL and test it to latest version. What plugins are being used?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "upgrade, backup" }
How to recover WordPress Adress(URL) I installed WordPress in localhost. I changed the WordPress Address from the general settings. After that none of the previous pages appears. Instead, a "Page Not Found" error page is appearing. I tried to change WordPress Address into previous one, but it doesn't happen. Now how can I recover the previous pages?
Edit file `wp-config.php` in root & define site url and home url: define('WP_HOME',' define('WP_SITEURL',' And go to admin dashboard and update permalink (Settings => Permalinks => Update).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "404 error, options, directory, localhost" }
do_shortcode() won't return PHP Array I have made a shortcode `[get_clients]` which is supposed to return an array of all the clients when called via `do_shortcode('[get_clients]')`. But all it returns is a string 'Array' only. Why?
This function returns a string. So you should join the elements of the array to make a string. From the Codex: > **Function Reference/do shortcode** > > Return Values > > _(string)_ > > Content with shortcodes replaced by the output from the shortcode's handler(s).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "shortcode" }
Replace taxonomy term with an image in a custom loop Just as the title says i want to replace the term from a custom taxonomy with an image, but **only in one custom loop** and not in the main loop. So i have a custom taxonomy named Tax1 that has two terms: Term1 and Term2. I use the following code to list the terms (i.e. Term1 or Term2) in the main loop: `echo get_the_term_list( $post->ID, 'Tax1', ' ', ', ', '' );` But for my custom loop i would like to have **an image** instead of the text term. I think this should be possible but i'm no good with php. **So how can i achieve this?** Thanks!!!
This is a quick and easy solution if you only have two terms and don't need a way to change those pictures in the backend. It assumes that inside your theme you have a folder "term_imgs" with *.png files names according to the slugs of your terms. $terms = get_the_terms( $post->ID, 'Tax1' ); $out = array(); if ( $terms && ! is_wp_error( $terms ) ) { if ( !empty( $terms ) ) { foreach ( $terms as $term ) { $out[] = '<a href="'.get_term_link( $term->slug, 'Tax1' ) .'"><img alt="'.$term->name.'" src="'.get_template_directory_uri().'/term_imgs/'.$term->slug.'.png"></a>'; } echo implode(',', $out ); } } You can call this folder however you want, just change the according piece of code, e.g. $out[] = '<a href="'.get_term_link( $term->slug, 'Tax1' ) .'"><img alt="'.$term->name.'" src="'.get_template_directory_uri().'/other_folder/'.$term->slug.'.jpg"></a>';
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, images" }
Programmatically add posts add and assign postmeta and assign terms I have thousands of WooCommerce products that need to be inserted into the database. For some reasons I can't use the csv import plugin or any other 3rd party solution and this has to be done manually through php code into database. Here is what my question is: > To what table do the product categories go ? I guess the products have to be added to `wp_posts` and then the description/price etc is added to the `wp_postmeta`. How to assign the products to a particular taxonomy. In which table do they go? Don't need the code just guidelines regarding tables.
The woocommerce product category is just a custom taxonomy. As far as I know all the data is stored as intended by wordpress core. You can find out more about the database structure at the codex page Database Description, the tables you are looking for are wp_terms, wp_term_relationships and wp_term_taxonomy. **But** you absolutely should look into doing this with available wordpress functions, like `wp_insert_post()` and `wp_set_object_terms`, it will make your life easier. Do a research on »programmatically adding post/custom post types« and »programmatically assign tags/categories«, here on WPSE is more then enough information about that available. Besides that you really, really should read the woocommerce source thoroughly, to make sure you're going to resemble all the steps creating a product correctly. Btw you can ask WooCommerce questions at the official WooCommerce Q&A. _Note:_ it just did not want to fit into a comment
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "terms" }
What would prevent a custom role from viewing posts (both standard and custom)? I am using a custom role (from the premium plugin wp-client) but for some reason it can't view posts or pages of any kind. WordPress shows the correct post count but only shows the message "No posts found". !Post count shows posts exist but they aren't displayed... Strangely, it is possible to edit the post content if you have the right edit url (i.e. example.com/wp-admin/post.php?post=XXX&action=edit). I have tried using multiple capability managers to assign the correct permission levels but this has no effect. This behaviour is identical across posts, pages and custom posts. Other custom roles made by the plugin can view everything normally. What could cause this?
This issue has been solved by an update to the plugin by the developers after prompting by support tickets. The WP-Client plugin is currently at v3.5.1
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, capabilities" }
How to add a description to the user name input field in the registration form? I want a description **under the user name input field** in the Wordpress registration form like in the next example. How can I do this? //create an extra field in login page for invitation code add_action( 'register_form', 'add_invitation_code_field' ); function add_invitation_code_field() { ?> <p> <label for="invitation_code"> Invitation code <input id="invitation_code" class="input" type="text" size="20" value="" name="invitation_code"/> <span class="description"><?php _e("Description text"); ?></span> </label> </p> <?php }
OK, that's possible using JavaScript (jQuery lib). Code - // load jquery on login screen if not loaded already add_action( 'login_enqueue_scripts', 'wpse_login_head' ); function wpse_login_head(){ wp_enqueue_script('jquery'); } add_action( 'register_form', 'wpse_register_form' ); function wpse_register_form(){ ?> <!-- we have used an unique id for the description tag --> <span id="user_login_description" style=" display:none;" class="description"><?php _e("Description text"); ?></span> <!-- the following line of code move the description after the username input --> <script type="text/javascript">jQuery('#user_login_description').appendTo('#registerform p:nth-child(1) label').show();</script> <?php }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "user registration" }
How Does One Create a Global Variable Repository This may have a simple answer but I would like to store all the variables I've declared ( or cached ) across my theme in a central file and serve then this file globally ( Similar to how `get_header()`, `get_footer()` and `get_sidebar()` works ). I've tried creating a file called `variables.php` and serving it via `get_template_part` but without success. For this particular project, it would be more convenient if the multitude of variables I've created across my theme were housed in a central location in lieu of being scattered throughout various theme files. Is there a idiomatic way of accomplishing this in WordPress?
A 'better' way of storing variables for global use is to use `add_option()` to cache variables and `get_option()` for retrieving variables. This way everything stored in the database and you can access it anywhere.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, customization, themes, variables" }
wp-editor is empty on first submit I'm using wp-editor in a simple plugin, but I'm having an issue where the first time I hit the submit button the content from it is blank in the database. <?php $editor_id = 'mycontent'; wp_editor($content, $editor_id ); ?> So I tried alerting the content using this: if (j(".wp-content-wrap").hasClass("tmce-active")){ alert( tinyMCE.activeEditor.getContent()); }else{ alert( j('#mycontent').val()); } and the first submit comes up empty. If I switch to the text version before I submit, it works. What am I doing wrong here that prevents the submit from working? Edit: Interestingly, if I do this: wp_editor('test', $editor_id ); It works. If I do this: wp_editor('', $editor_id ); It doesn't work again. How do I get it to work if the `$content` is initially blank?
I just had the same problem. the submit of content of the wp_editor works not at first-submit, but perfect on second submit. Another way: Click on the html-button, and then click on the "Vusual"-Button. I do it with this jquery-statements in my jquery-code to submit the form: $("#post_content-tmce").click(); $("#post_content-html").click(); These 2 lines before the $.post-statement makes the content of the editor visible, and submit works.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp editor" }
How to turn off redirection from 'domain.com/login' to 'domain.com/wp-login.php' I want to install something different than wordpress under 'mydomain.com/login', but WordPress automatically redirecting this link '/login' to '/wp-login.php'. Where can I turn off this redirection?
If you look at `canonical.php` you will notice that the `wp_redirect_admin_locations` function is hooked very late-- at priority 1000. This means that just about any function hooked to `redirect_canonical` runs before this one. So, conditionally remove `wp_redirect_admin_locations` from the `template_redirect` hook. add_action( 'template_redirect', function() { $requ = untrailingslashit($_SERVER['REQUEST_URI']); if (site_url('login','relative') === $requ ){ remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 ); } } );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "php, redirect, login" }
How to change the menu like this? Here is my `wp_nav_menu`: wp_nav_menu( array( 'link_before' => '<span><strong>', 'link_after' => '</strong></span>' ) ); I got `a` tag like this: <a title="TITLE" href="..."><span><strong>LINK</strong></span></a> But I actually need this: <a href="..."><span><strong>LINK</strong>TITLE</span></a> Is it possible to write a filter?
You need to create a custom walker. Specifically, create a child class of `Walker_Nav_Menu`. The only funciton you need to override is `start_el()`. Copy it wholesale into your class, and place the title where you want it. Then in your `wp_nav_menu` call, specify your walker. <?php wp_nav_menu( array( 'link_before' => '<span><strong>', 'link_after' => '</strong></span>', 'walker' => new My_Custom_Walker() ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus" }
Rewriting URL does not automatically log me in I've installed my blog at `www.mysite.com/blog` I want to re-write the URL to take out the `blog` part so you can access it at `www.mysite.com` I added a rewrite rule in `.htaccess` file, but I noticed that when I go to the rewritten URL, I am not logged into my account; I would have to go through the original `/blog` to be logged in. What is the problem here and how can I solve it?
Wordpress has support for installing in a different directory to your desired home directory. Have a read of the two bullet points near the top of this page: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "url rewriting" }
Change email for update notification I've recently got the email with the update notification. `[Example.com] Your site has updated to WordPress 3.8.1` `Howdy! Your site at has been updated automatically to WordPress 3.8.1. [...]` **I want to change the email where this notification goes.** I seems that it's not connected with any user. I've searched all the backend and I can't seem to find the required setting.
The setting you are looking for is found in "Settings"=>"General"=>"E-Mail Adress". All the Emails WordPress or Plugins send out are sent to the `admin_mail`, which is returned by `get_option( 'admin_mail' )`, and this Emailadress is not always connected to a user. If you first install WordPress, the first user created gets the role `administrator`, and the same Emailadress is used for this setting, but can be changed afterwards. This actually makes a lot of sense, as a site could have a few administrators (or none, to be picky). Not everybody needs to get this information, as well as someone _should_ get it, even if a site does not have an administrator registered in the database. This is the reason for the two distinctive fields/settings.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "automatic updates" }
importing plugin w/ settings from one WP installation to another Is there a way to import plugins (and their settings) from one WP installation to another? I've found various tools and tutorials for exporting/importing entire WP installs, posts and pages, etc. but nothing for plugins & plugin settings.
As every plugin is unique in how and where it stores its data there is no standard process to do this. Some plugins might still offer an import/export functionality themselves. I'm sorry but WordPress doesn't offer the functionality out of the box.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins" }
Re-directing URLs with dates to URLs without dates When I first started writing entries I decided to include the month and day in the URL's, thinking I might need them. In the end turns out I didn't. I found that I can access a particular entry as Typing in the second one would simply lead to a 301 redirect to the first. Is there a way to make it so that typing in the long form with the date would re-direct to the second without breaking any permalinks?
You just have to set your permalinkstructure to `/%postname%/`. Special rewrite rules do not need to be done here, as this is a simple setting WordPress handles on it's own.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "url rewriting, redirect" }
How can I allow users to make groupings of posts I have a site with many research methods. I want to introduce the abilities for users to create groups of posts and save them for others to access, as a way to make the methods more meaningful for different types of people and applications. Any advice for achieving this. The site is < I want front end users to do it. The best analogy would be user-generated playlists.
The simplest way to "group" posts are post tags and categories. Both are built in.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "user access" }
What for is the table "wp_commentmeta" exactly? I have been reading about the Database Description of Wordpress. I haven't understood the meaning to the use of the table `wp_commentmeta`. The documentation says: > Each comment features information called the meta data and it is stored in the wp_commentmeta. I have a fair idea of what meta-data is. I know how the table `wp_postmeta` stores custom field, for example. But in the case of the comments, I don't understand: * What kind of information would go in this table? * Why wouldn't it be in the same `wp_comments` table? * What is a practical example of how someone would use it, so that I could test it out and have a more graphic idea of how it works?
That table is essentially the same as for all of the other "meta" tables in the WordPress architecture. It holds misc. bits of extra, usually optional, information about the associated post, user, or in this case comment. You can store whatever information you need to add to a comment-- perhaps a plugin wants to implement "abuse" flags, or comment upvotes. It can really be just about anything. This information would not go in the comments table because it is usually optional and additional, and has no predefined meaning. How many extra columns would you put in the comments table "just in case"? See what I mean. You can see an example of use in the Codex entry for `add_comment_meta`. function add_custom_comment_field( $comment_id ) { add_comment_meta( $comment_id, 'my_custom_comment_field', $_POST['my_custom_comment_field'] ); } add_action( 'comment_post', 'add_custom_comment_field' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 7, "tags": "comments, database, table, comment meta" }
Completely hide user info I'm wondering if there's a way to make 100% sure a user's info is not available to the public. Our theme is not currently using a profile page, but I did notice that there is a 'Posts by author' page for each user. Aside from that, is there anywhere else a user's info may show up? I'm hoping to have no info be displayed anywhere on the site, including a user's email address, name, username, etc. The reason for this is that our WordPress user's will have very sensitive information, and that they will not want to be public in any way shape or form. > Question: Where in public/not logged in request can author info be exposed?
This is dependant on your theme/plugins so it's impossible to answer, as s_ha_dum mentioned. For example some themes output the author name in the body as a class like `<body class="author-keanu">` or maybe they just use the author id like `<body class="archive author-22">` and then you can check the author by going to `www.example.com/?author=22` and maybe the template hierarchy has an author page, or a plugin added one, or maybe not. _Since there are **lots** of WP functions that can output/or use author/nicename or author id's the only real solution is to audit your theme/plugin code._ Another important note is that you can guess if a username exists using WP's login. for example if you guess an existing username of "Jane" the error will be: > ERROR: The password you entered for the username Jane is incorrect.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "users, author, profiles, privacy" }
Migrating Users along with their password I would like to migrate users from one wordpress site to another along with their paasswords, there are 15000 users in total . what would be the best way to do this . is a migration of the database tables wp_users and wp_user_meta recommended ? Thanks
I imported the 2 tables in the target database and faced permission issue while logging in to the target site , then I followed this site < and it fixed the issue.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "users, migration" }
Create A Metabox For A Custom Field I add videos to my WordPress posts' video format by using custom fields. I was wondering if there is any way to create a meta box in post editor (like excerpt or something) for that specific custom field. Just a text area to add iframe code. For example the custom field is a embed-video.
This will create a metabox for you to enter a video code. //Creating a MetaBox for Posts to enter Video Code. add_action('add_meta_boxes','video_meta_box'); function video_meta_box(){ add_meta_box('video_box_id', 'Enter Video ' , 'video_box_cb','post','normal','default'); } function video_box_cb($post){ $value = get_post_meta($post->ID,'video_box',true); echo '<textarea rows="4" cols="50" id="video_box", name="video_box">'; echo $value; echo '</textarea>'; } add_action('save_post','save_video_box'); function save_video_box($post_id){ $box_data = $_POST['video_box']; update_post_meta($post_id,'video_box',$box_data); } Use this code to render this code within your theme. <?php $custom_values = get_post_custom($post->ID); echo '<p> Video CODE: '.$custom_values['video_box'][0].'</p>'; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "posts, custom field, metabox" }
Resolve a custom post type name vs. page permalink conflict (same slug) I have a custom post type called "visningshus", and also a Page with that slug. This is as it should (must) be. Currently, "< lists all posts of that type. I want to show the page that has that permalink slug instead. How can I make Wordpress not make the post type name take precedence, but instead the permalink, and show the Page?
The easiest would be to just disable the archive page for this CPT: register_post_type( 'visningshus', array( [...] 'has_archive' => false, [...] ) ); Don't forget to refresh you permalinks afterwards at _"Settings > Permalinks"_
stackexchange-wordpress
{ "answer_score": 48, "question_score": 31, "tags": "custom post types, permalinks, redirect" }
Add Shortcode tag in Widget/Sidebar I want to add a shortcode tag in the sidebar/widget. I am able to get the required functionality if I add the code in the theme's function.php add_filter('widget_text', 'do_shortcode'); My problem is that I am searching for a way I can do this from the plugins files itself without affecting any of the theme files. Can anyone tell me if this is possible?
Here is your plugin: <?php /* Plugin Name: Do shortcode in side-widget Description: Let's do it. Version: 0.1 Author: CyberPanda */ add_filter('widget_text', 'do_shortcode'); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, widgets, shortcode" }
The Hook registration_errors was not called I can't validate the custom fields in my plugin. I want to skip some registration on WordPress. My code snippet is here: add_filter( 'registration_errors', 'reg_user_register', 10, 3); function reg_user_register($errors, $sanitized_user_login, $user_email){ global $wpdb; echo "<pre>"; /*need the values that are post from registration page*/ print_r($_POST); exit();} }
You are not using the registration_errors hook properly. It should look like this: add_filter( 'registration_errors', 'reg_user_register', 10, 3); function reg_user_register($errors, $sanitized_user_login, $user_email){ $custom_reg_field1 = $_POST["custom_reg_field1"]; // add error checking here if ( empty($custom_reg_field1) ) { $errors->add('custom_reg_field1', __( 'Please enter a reg_field1.' ) ); } return $errors; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, hooks" }
What tool are available in the wordpress API for debugging a plugin? I am very new to plugin development. I have created my first plugin but when I activated it, it caused the majority of every page on the site to stop being generated. I have echoed something from the end of the php script to confirm that it was completing without an error. But other than that I have no idea what I should do to debug this problem. I would like to be able to work on this on a public site that will be getting traffic while I work, is there a way I can have the plugin only activated on one page or only for me and not for guests? I would like to be able to show debug messages, is there a convenient way to do this? Are there points outside of my plugin that would be helpful for debugging? I don't know where to look that might be leading to the problems.
## 1\. You should _NEVER_ work on a live site Just setup a local installation of WAMP or MAMP and do your testing there. This has a lot of benefits: * You can't break a live site * You don't need to upload changed files * It runs faster as everything is local and doesn't go trough the internet ## 2\. Debugging First you could enable debug in _config.php_ define('WP_DEBUG', true); This will give you a lot more information **what** went wrong if something goes wrong. There also is a lot more info in the WordPress Codex on Debugging in WordPress
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, debug" }
How can i fix a 404 error when targeting custom taxonomy slug ? I have defined my new taxonomy like this $args = array( 'labels' => $labels, 'show_tagcloud' => false, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'activites', 'hierarchical' => true ), ); register_taxonomy( 'business_category', 'business', $args ); I have no custom rewrite rules. this url works : calling my taxonomy-business_category.php template. so i want to reach this url now : but it throws a 404. the purpose (besides having a functional breadcrumb) on this page is to list all my custom category terms. how can i target a page that englobes all categories ? is it a rewrite conflict or a rewrite missing ? thank for your further explanation.
There's nothing missing or broken, this is expected behavior. There is no concept of an archive of taxonomy _terms_ , archives contain _posts_. It makes sense if you think about it - the main query always contains some sort of collection of posts, which are output by The Loop, there's no way for that to instead be a collection of terms. A simple fix is to create a page with slug `activites`, create a Custom Template for that page, and output your taxonomy's terms within that template.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, url rewriting" }
Check if do_action('custom_action') is hooked into? Is there a way to check if a custom hook gets called upon? I would like to display a placeholder if no output will be passed to it.
I believe you are looking for `has_action`, which should ... > Check if any action has been registered for a hook. if (has_action('custom_action')) { // stuff } else { // different stuff }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "hooks, actions" }
Blogger To WordPress Permalink Redirection Is there any way to redirect following or anything permalink like this: < to < Any link with a .html in the end to / in the end.
You can set up the redirection on the .htaccess file, adding this row: RewriteRule ^\d{4}/\d{2}/(.+)\.html$ [R=301,L]
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, redirect, blogger" }
Redirect Attachment Page to Attachment I'm trying to change my attachment page to just automatically redirect to the attachment. Here's what I've tried: Get attachment ID and redirect to that URL: $urlArr = wp_get_attachment_image_src($_GET['attachment_id'], 'full'); if(empty($urlArr)) $url = wp_get_attachment_url($_GET['attachment_id']); else $url = $urlArr[0]; wp_redirect($url, 301); exit; The redirect to a textual version of the image, I've tried to send extra headers but run into a problem that headers have already been set... I've searched for it online but only found links where people want to redirect to a certain page, but I'm trying to redirect to the media itself, plugin free. I'm adding the above code directly into `attachment.php` template file.
You can't redirect after content has already been sent to the browser, hook an action before the template is loaded and do your redirect there. function wpa_attachment_redirect(){ if( is_attachment() ){ // your code and redirect here } } add_action( 'template_redirect', 'wpa_attachment_redirect' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "redirect, attachments, media, wp redirect" }
Override the Wordpress core function wp_referer_field I'd like to override the core Wordpress function wp_referer_field to change the value of $referer_field variable inside of it. I've found that wp_referer_field is not pluggable and that I need to use some other technics for that. Adding some filters or actions. I was trying to use these code: add_filter( 'wp_referer_field' , 'wp_referer_field_cyrillic' ); function wp_referer_field_cyrillic( $echo = true ) { $referer_field = '<input type="hidden" name="_my_wp_http_referer" value="'.urldecode(esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) )) . '" />'; if ( $echo ) echo $referer_field; return $referer_field; } But it doesn't work. It seems that I did something wrong.
`wp_referer_field` is a _function_. You cannot treat a function like a _hook_. That isn't how hooks work. That is, you can't hook into a function name. Hooks are intentionally created. (And there are no hooks built into that function) Secondly, you can't override a function at all, as a rule. Some few functions in WordPress are wrapped in an `if(function_exists('..'))` conditional. Those are the exceptions. Those can be replaced by creating a new function of the same name, but not by "hooking" into them. There may be another way to do what you are trying to do if you were to explain the problem in more detail. See: * Override parent theme function that is not hooked or in the functions.php file * How to override shortcodes.php core file? * Clarification on filters and hooks
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, filters, hooks, actions" }
New Wordpress Error Message - Not seen this before I've just seen a new error message on one of my Wordpress sites that I've not come across before. **_"This request has been denied for security reasons. If you believe this was in error, please contact support."_** As usual, I hopped onto Google to see why this was coming up, but short of a few others also finding this message there's very little out there on this. Does anyone know what it is? Is it new? A part of Wordpress? It doesn't really offer much in the way of explanation. I'm guessing it's an IP ban of some sort, but I'm not sure where... !Boring error message
It could be that a plugin which blocks I.P addresses or Countries is causing this. Otherwise it maybe a setting in a security plugin has caused this. Seems the message is a custom one. Otherwise it could be something coded into a .htaccess file.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "errors" }
How to prevent first post and first comment on WP MU? When a user creates a new blog a new post and a new comment is created at the same time. Is there a way to disable this?
I usually just run a function on **wpmu_new_blog** \- best to put in **mu-plugins** function wpse_wpmu_remove_default_content($blog_id, $user_id, $domain, $path, $site_id, $meta) { if ( !current_user_can('manage_network') ) return; switch_to_blog($blog_id); // Remove the default post & page wp_delete_post(1, true); wp_delete_post(2, true); // Remove the first comment wp_delete_comment( 1, true ); restore_current_blog(); } add_action( 'wpmu_new_blog', 'wpse_wpmu_remove_default_content' );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "multisite, customization, installation" }
Is there anything special I have to think of when setting post_date_gmt when inserting a new post? I'm inserting information from a user into a custom post type. `$current_user` it a user-object. Is there anything special I have to think of when setting `post_date_gmt` when inserting a new post with wp_insert_post? (Or could I just fetch the value from the user-table like below? $pupil = array( 'post_title' => $current_user->display_name, 'post_date' => $current_user->user_registered, 'post_date_gmt' => $current_user->user_registered, 'post_type' => 'pupil', 'post_status' => 'private', //This registration cpt is not available for public 'post_author' => $current_user->ID ); $postid_pupil = wp_insert_post( $pupil )
Most of the times, you can just leave it empty and the wp_insert_post will take care of handling it but if you want to set it use php's function: gmdate("Y-m-d h:m:s", strtotime($current_user->user_registered)) which works exactly like the php date function.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "date, wp insert post" }
Why can't I update username through Wordpress API? I'm just wondering about usernames... Why isn't is possible to change this through Wordpress API? (I understand why a user in the admin dashboard can't change username(s) but that isn't really same thing!?) Code below does just ignore the user_login - setting. $pupil_obj= get_post($postid_pupil); $user_login = $pupil_obj->post_name; $user_nicename = $pupil_obj->post_name; $user_args = array( 'ID' => $current_user->ID, 'user_email' => $email, 'user_login' => $user_login, 'user_nicename' => $user_nicename ); wp_update_user( $user_args ) ; I could update the username to the database directly through `$wpdb`. This makes no sense to me. Can someone explain?
Looking on Trac I found a ticket that discusses exactly this issue: Administrator should be able to change usernames This is what it all boils down to: ## Changing usernames could break permalinks To prevent this a lot more than just changing the username in the DB would need to be done. E.g. redirection from old usernames. ## Caching Issues I quote from the aforementioned Ticket: > "One problem you could get, if you do this using the db while using memcached, is the the old value remains in the store until memory runs out." > > Denis-de-Bernardy ## TL;DR It may cause various problems and therefore is intentionally difficult to do. In case you think of this differently fell free to join the discussion in the corresponding ticket.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "updates, username" }
Blank line before doctype I have a frustrating problem. In the page source, the first line is blank, which causes issues in some browsers. These are the steps I've taken to try to fix the problem: * Gone back to twentythirteen theme * renamed plugins folder to oldplugins. Checked in admin and they are all deactivated * Made sure there is nothing outside of the php in index.php, header.php * cleared out htdoc htaccess I'm at a loss!
In this instance, there was a carriage return after the closing php tag in wp-config.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, headers" }
How to redirect custom post type archive to first term of associated taxonomy? I have a custom post type 'countries' and a taxonomy 'cities'. My cities are: boston, new york... I want my `archive-countries.php` redirect to the first term taxonomy. I mean, if my URL is `www.example.com/countries` this should redirect to `www.example.com/cities/boston`. How can I do this?
If you know you're loading the right template, redirect to your first term of the specified taxonomy: function wpse_135306_redirect() { $cpt = 'countries'; if (is_post_type_archive($cpt)) { $tax = 'cities'; $args = array( 'orderby' => 'id', // or 'name' or whatever ); $cities = get_terms($tax, $args); if (count($cities)) { wp_redirect(get_term_link(reset($cities), $tax)); exit(); } } } // function wpse_135306_redirect add_action('template_redirect', 'wpse_135306_redirect'); **References** : * `template_redirect` * `is_post_type_archive` * `get_terms` * `wp_redirect` * `get_term_link`
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom taxonomy, redirect, custom post type archives" }
How can I display a specific user's first published post? I'm looking for a way to display a user's first published post using their unique ID. I have a function that calls a list of specific users using their IDs, and would like to display the date the user first published a post. This is the code I put in, however, the cells return blank with no PHP errors in the log. $useremail = $ticket['email']; $user = get_user_by( 'email', $useremail ); $IDuser = $user->ID; $args = array( 'posts_per_page' => 1, 'post_status' => 'publish', 'author' => $IDuser, 'orderby' => 'ID', 'order' => 'ASC', ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { $first_post->the_post(); echo the_time('M j, Y'); wp_reset_postdata(); }
The following query retrieves the **oldest** post of a specified user/author: $user_id = 42; // or whatever it is $args = array( 'posts_per_page' => 1, 'post_status' => 'publish', 'author' => $user_id, 'orderby' => 'date', 'order' => 'ASC', ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { $first_post->the_post(); // Now you can use `the_title();` etc. wp_reset_postdata(); } If you want to show the **first** post a specific user wrote (no matter what the post's publish date is set/altered to), then you have to use `'orderby' => 'ID',`.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "posts, query, date, publish, id" }
search form leads to 404 I'm using the follow code in my functions.php to add a search box to my primary nav menu - add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2); function add_search_box_to_menu( $items, $args ) { if( $args->theme_location == 'primary' ) return $items."<li class='menu-header-search'><form action='search.php' id='searchform' method='get'><input type='text' name='s' id='s' placeholder='Search'></form></li>"; return $items; } The form adds to the nav menu ok, but any search attempt leads to a 404 message. What have I missed?
Don't submit directly to `search.php`. WordPress probably will not know what to do with that. You will have the same issue submitting directly to any theme file. WordPress should pick up on the `s` parameter and process the search correctly if you just leave out the `action` attribute like so: <form id='searchform' method='get'> Untested, but I am fairly confident.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, menus, filters, search" }
JQuery plugin that works with Google 1.10.2 and not with Wordpress 1.10.2 I'm making a custom implementation of JQuery Colorbox in a Wordpress plugin. However, it's not working with my default Wordpress installation. After tinkering a bit, it comes down to the inclusion of the JQuery library. Neither of these lines work: `<script src=' `<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>` But either one of these do: `<script src=" `<script src=" I've tested that JQuery works with all of the above by using: if (typeof jQuery != 'undefined') { alert("jQuery library is loaded!"); }else{ alert("jQuery library is not found!"); } It passes on all four of the script links I've tried. If I change that one line on Jack's demo page, it breaks as well. Is this a colorbox issue? < Could you guys help me see what I'm missing here? I'm stumped.
Try placing your code in this (function($) { // Inside of this function, $() will work as an alias for jQuery() // and other libraries also using $ will not be accessible under this shortcut })(jQuery); I'm suspecting your code uses `$`, which is normally an alias for `jQuery` but doesn't work globally because WP's version of `jQuery` is in no conflict mode. `$` will work if the code is placed in an enclosure such as the one above.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, jquery" }
List users with the most posts in the last 30 days I'm trying to create a MySQL query to display a descending list of users with the most number of posts over the last 30 days. This is not working with me: $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; $top_users = $wpdb->get_results("SELECT COUNT(ID) AS post_count, post_author, post_date, user_id FROM $wpdb->posts, $wpdb->usermeta WHERE $wpdb->posts.post_author = $wpdb->usermeta.user_id AND post_type = 'post' AND post_status = 'publish' $where");
Here is what you need. <?php $date = new DateTime('NOW'); $date->sub(new DateInterval('P30D')); //30 Days Interval echo $back30days= $date->format('Y-m-d H:i:s') . "\n"; global $wpdp; $top_users = $wpdb->get_results("select count(users.user_nicename) as posts, users.user_nicename as user_name from $wpdb->users as users join $wpdb->posts as posts where users.ID = posts.post_author AND posts.post_status='publish' AND posts.post_date_gmt > '$back30days' GROUP BY users.user_nicename ORDER BY count(users.user_nicename) DESC"); echo '<h3>In Past 30 Days</h3>'; foreach ($top_users as $top_user){ echo '<p>'.$top_user->user_name.' has written '.$top_user->posts.' posts</p>'; } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "mysql, wpdb, phpmyadmin" }
Back up post tags What is the best way to back up tags on posts? I want to delete all existing tags on all post types, but want to be able to restore them if something goes wrong..
Just export the wp_terms table (or *_terms if you have a custom prefix) as a .sql file, then truncate the table. This will clear them all. If you want to put them back on, just import the .sql file you just created. Hope this helps
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, tags" }
how to remove +new from wp admin area I work on a project in which I want to remove +New link in WordPress admin bar. Actuly i want to replace 'new' to 'ADD Deal'. Is there any function in WP with this we can replace this text or how can I do this.
I think what you are asking is changing the text +NEW to ADD Deal. This code is adjusted like that. add_action( 'admin_bar_menu', 'change_new_post_name', 999 ); function change_new_post_name ( $wp_admin_bar ) { //Removing +New $wp_admin_bar->remove_node( 'new-content' ); //hyperlink for the new link. This can be anything. Currently it's default. $link = get_bloginfo('url').'/wp-admin/post-new.php'; //Parameters to create a new node $args = array( 'id' => 'new-content', //re-creating the +New 'title' => 'ADD Deal', //Giving it a different title 'href' => "$link" // Above created link ); $wp_admin_bar->add_node( $args ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "admin" }
Save temporary registration data I am working on a custom signup proces, where user first sign up with their name and email and after that they gonna add their company (a post in post type 'companies'). After they have signed up with their name and e-mail the receive an e-mail with a registration link. I need to save their data temporary, so if they click the link, their name and e-mail be retrieved back from the database. What is the best option to save this data a Wordpress way. Use option table? I cannot save it in Session because some people read their e-mail a week later for example.
You could save this as `user_meta` using `[add_user_meta][1]`. The options are usually used for sitewide settings, whereas the `user_meta` is specific for the single user. add_user_meta( $user_id, $meta_key, $meta_value, $unique ); You can either delete the data on activation of the account, or leave it there - I do not see why you would want to delete it. So the process should be * create user * add user meta * send registration email * your custom activation stuff Everything okay so far?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, theme development, database" }
Change CSS on tag in tagcloud, if ther current post is tagged with the tag My tagcloud are placed in the sidebar (outside the loop). I want to give the tags in the tagcloud a class if the current post is tagged with the tag. How do I do this? - something id wrong :( This is my PHP-code: $tags = get_tags(); $post_tags = get_the_tags($currentid); if ($tags) { foreach ($tags as $tag) { if( (is_tag($tag)) || ($tag->name == $post_tags) ){ echo '<a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'" class="currenttag">'.$tag->name.'</a> '; } else { echo '<a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'"">'.$tag->name.'</a> '; } } }
`get_the_tags` will return an object of tags so you will have to make an array of the post tags and then see if the `$tag->name` is in the post tags array. $tags = get_tags(); $post_tags = get_the_tags($post->ID); /* Just make an array so you can use in_array function later on */ $post_tag_array = array(); foreach( $post_tags as $post_tag ){ array_push($post_tag_array,$post_tag->name); } if ($tags) { foreach ($tags as $tag) { /* Then change to search this array for the $tag->name */ if( (is_tag($tag)) || ( in_array($tag->name, $post_tag_array )) ){ echo '<a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'" class="currenttag">'.$tag->name.'</a> '; } else { echo '<a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'"">'.$tag->name.'</a> '; } } } Hope this helps
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "tags" }
Using wp-cli to Update WP Networks / Multisite from 3.5.1 to 3.8 I've been handed a WP Networks site that is running WP (Networks) 3.5.1 on RHEL 5.8 with about 40 sites attached to it. I see the need to update to 3.8. By background, I'm more familiar with maintaining Drupal sites with `Drush`. My first hunch here is to use `wp-cli` to run the update. Is this the preferred update method in the WP community or am I better swapping out php files from the tar ball? That is, can I depend on `wp-cli` to run a clean update from 3.5.1 to 3.8? Many thanks!
For regular users, the preferred update method is pressing the "Update" button in wp-admin. For sysadmins, `wp core update` \+ `wp core update-db` will probably be a lot faster. Note that for multisite instances, you'll have to update the DB for each site in the network. See < NB: I might be biased, since I'm currently the maintainer of WP-CLI.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "updates, wp cli" }
Is wordpress compressing my images? if so, how to prevent it? I am using 'featured image' fields in my post and the images are sized and compressed already but whenever I upload an image that has some text, I keep noticing the image reduced in quality (specifically, the text in the image). Is wordpress compressing my images? if so, how to prevent it?
A nice explanation is at WPMUdev: < According to their tutorial, you'd need to add the following to your `functions.php` `add_filter( 'jpeg_quality', create_function( '', 'return 100;' ) ); ` They also suggest regenerating your thumbnails once the change is made so previously uploaded images will be affected by the quality change.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, images, compression" }
Top menu link anchor href value change after online server? I was recently launch localhost server on my computer to create local website. If I create new link that add to top menu. The href value was < Does this href value will change to my website name after I upload my website online ? <
Sure it will change if it was created using the default WordPress menu. Wordpress stores a site url, which is usually the domain or exact path. On your localhost it will be something like localhost/site/about and the moment you deploy your site and update your database with your domain, www.yourdomain.co.za/ - that will automatically update the rest of the pages or links, e.g. www.yourdomain.co.za/about So, to answer your question: Yes, but only if your used the WordPress menu
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus, links" }
Posts are duplicating on wp_post_update I have stucked in writing a simple function that on certain page update refresh all posts in a custom post type. Here is my code (based on this): add_action('save_post', 'bulk_refresh'); function bulk_refresh($post_id) { if($post_id != 123)//123 is the 'certain page' id return; $posts_to_update = new WP_Query(array('post_type' => 'MY_CUSTOM_TYPE', 'posts_per_page' => -1)); while($posts_to_update ->have_posts()) : $posts_to_update ->the_post(); $args = array( 'ID' => $post->ID ); wp_update_post( $args ); endwhile; // Reset Post Data wp_reset_postdata(); } On first sight all must be working fine, but when I save the page with id '123' all posts in the custom post type are duplicated. I want just to 'refresh' them. Any ideas where I am wrong?
Ah, I found the answer myself. I've added global $post before the loop and now all seems to works fine. I don't know if this is a good practice, so if you have another ideas share them :) Here is the revised code: add_action('save_post', 'bulk_refresh'); function bulk_refresh($post_id) { if($post_id != 123)//123 is the 'certain page' id return; global $post; $posts_to_update = new WP_Query(array('post_type' => 'MY_CUSTOM_TYPE', 'posts_per_page' => -1)); while($posts_to_update ->have_posts()) : $posts_to_update ->the_post(); $args = array( 'ID' => $post->ID ); wp_update_post( $args ); endwhile; // Reset Post Data wp_reset_postdata(); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, hooks, page template, wp update post" }
Broken comments section - Wordpress 2014 Theme I recently switched my Wordpress theme to the "default" 2014 one. Everything looks great, except I'm having trouble with comments showing up correctly. Can somebody help me understand what's wrong? See <
It turns out there was an issue with the minification of some things on my site. Disabling/clearing the cache seemed to have solved the issue.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments, theme twenty fourteen" }
Changing the display of the themename_posted_on() function At present, this is what the `pl_dev_posted_on()` function is displaying: !pl_dev_posted_on\(\) Where can I find this function to be able to edit what it displays?
This question is entirely Theme-dependent. The function will be defined in `functions.php`, or in a file included in `functions.php`. Based on the function name, I'm going to take a guess that the Theme in question is derived from Underscores, in which case the function will be defined in `/inc/template-tags.php`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "single" }