question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
This code works perfectly <code> function exclude_category( $query ) { if ( $query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query() ) { $query-&gt;set( 'cat', '-1' ); } } add_action( 'pre_get_posts', 'exclude_category' ); </code> But this code does not work at all <code> $caid = "-1"; function exclude_category( $que...
<code> $caid </code> is unknown inside the function, unless declared global. <code> $caid = '-1'; function exclude_category( $query ) { global $caid; if ( $query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query() ) { $query-&gt;set( 'cat', $caid ); } } add_action( 'pre_get_posts', 'exclude_category' ); </code> // Edit...
pre_get_posts for exclude category
wordpress
I created a plugin that adds a function to the registration process where the user info also gets added to an external db. The problem is that, when the function runs successfully i.e. user is able to be added to the external db, but the wordpress registration process returns and error, the user is still added to the e...
The variable <code> $errors </code> is an instance of <code> WP_Error </code> . WordPress has done all internal logic before the filter is used, so you can check for existing errors: <code> function add_user_to_SF($errors, $sanitized_user_login, $user_email ) { if ( $errors-&gt;get_error_code() ) return $errors; global...
Structuring function with registration_errors hook
wordpress
I built a custom search with the following code: functions.php <code> function template_chooser($template) { global $wp_query; $post_type = get_query_var('post_type'); if( $wp_query-&gt;is_search &amp;&amp; $post_type == 'products' ) { return locate_template('archive-search.php'); // redirect to archive-search.php } re...
This is not related only to your custom post_types search. WordPress has a problem on empty search on itself. I use this simple code snippet as workaround: <code> add_filter( 'request', 'my_request_filter' ); function my_request_filter( $query_vars ) { if( isset( $_GET['s'] ) &amp;&amp; empty( $_GET['s'] ) ) { $query_v...
Problem with custom post type search
wordpress
I've found this simple yet elegant solution for make Wordpress using the same template category on every child and grandchild categories stackexchange-url ("stackexchange-url Full code: <code> function myTemplateSelect() { if (is_category() &amp;&amp; !is_feed()) { if (is_category(get_cat_id('projects')) || cat_is_ance...
I managed to solve this in a procedural way: 1 added in theme function this snippet: add_action('template_redirect', 'load_category_tree_template'); <code> function load_category_tree_template() { if (is_category() &amp;&amp; !is_feed()) { // replace 'your-base-category-slug' with the slug of root category $base_tree_c...
Wordpress a template for subcategories fo a given category, but not for root category
wordpress
I am working on site. I uses some custom <code> error/success </code> messages for front end form but currently it display messages to on same page, But as soon as I refresh the page or redirect the user to next page messages not save. To save the <code> success messages </code> I use the <code> code </code> <code> $su...
You could save the messages in a <code> $_SESSION </code> variable. This way, the values will be preserved untill you decide to remove them again. <code> function save_message( $type, $message = '' ) { $_SESSION['messages']['type'] = $message; } function get_messages() { $return = ''; if ( isset( $_SESSION['messages'] ...
How we store error/success messages to the next page
wordpress
I would like to allow my subscribers to post classifieds, which are nothing but a custom post type with a few metas for the price, etc. (The existing classifieds plugins I have tried are way too complex for my needs.) I would like to know if the following makes sense. I define a [classifieds-form] shortcode displaying ...
Alway send submissions to the page the form is displayed. In your shortcode callback you can then display proper error or success messages. Sample: <code> add_shortcode( 'classifiedsform', 'classifiedsform_callback' ); function classifiedsform_callback() { if ( 'POST' !== $_SERVER['REQUEST_METHOD'] or ! isset ( $_POST[...
Using shortcodes to parse POST request (containing the data from a front-end form)
wordpress
I am writing a simple plugin that create a table with name "newsletter" in database and provide a shortcode to put a registration form in pages. the form contain "name" and "email". i have problem with inserting the form data(name+email) in database. i wrote this: <code> &lt;?php $name = $_POST['name']; $email = $_POST...
The two variables <code> $name </code> and <code> $email </code> are unknown inside the function. You have to make them globally available inside it by changing <code> global $wpdb </code> into <code> global $wpdb, $name, $email </code> : <code> require_once('../../../wp-load.php'); /** * After t f's comment about putt...
Insert data in database using form
wordpress
I'm using the Wordpress Bootstrap theme as my base theme. It uses the following code to add the class "active" to any links in the header if the user is currently on that page: <code> add_filter('nav_menu_css_class', 'add_active_class', 10, 2 ); function add_active_class($classes, $item) { if($item-&gt;menu_item_parent...
Not the cleanest solution, but I use something like this for a few instances of current page menu highlighting for pages that aren't child/parent related in any way: <code> &lt;?php if (is_page('tutorials-by-topic') { ?&gt; &lt;script type="text/javascript"&gt; jQuery(function($) { $(document).ready(function() { $('#me...
How to add active class to separate page link?
wordpress
It seems like something really simple, however I can't find a good solution to what I am looking for. I created a page template that shows all my taxonomy term of a taxonomy called " news " eg: paper1, paper2 etc etc this is the code I generated: <code> &lt;?php $post_type = 'article'; $tax = 'news'; $tax_terms = get_t...
You're not setting an order anywhere for <code> get_terms </code> , you're setting it for the query of articles within each term . You need to pass arguments to <code> get_terms </code> if you want an order other than default, which is <code> ASC </code> . <code> $tax = 'news'; $tax_args = array( 'order' =&gt; 'DESC' )...
Order taxonomy terms wordpress
wordpress
Does anyone know if it's possible to use a page template on a URL, even if a page doesn't exist for that page? When building sites, I create the relevant pages to ensure use of the templates, but then if the site admins later delete that page, it breaks the site. I'v read that it's possible to add custom URL rewrites, ...
What I would advice, and have done myself when making WordPress sites for clients. Create a custom post type that they can’t get access to. You can achieve this by conditionally removing the post type from the admin sidebar. One of the ways to solve that problem is to add a custom capability to the user(s) that you wou...
Using a page template without a page
wordpress
I have created a common custom dashboard for my users located at " http://website.com/login/dashboard/ " I'm trying to redirect users to that custom dashboard only if they are NOT admins &amp; if the page IS http://www.website.com/login/wp-admin/ The redirection function I have is: <code> add_action( 'admin_init', 'red...
You can test for roles with <code> current_user_can() </code> : <code> if ( is_admin() &amp;&amp; !current_user_can('administrator') ) { // redirect } </code>
Check if current page is wp-admin
wordpress
I'm trying to get the page parent dropdown (in page attributes) to show only pages that have been published by the author of the current page. This doesn't seem to work : <code> add_filter( 'page_attributes_dropdown_pages_args', 'mwm_show_only_author_pages_in_attributes' ); add_filter( 'quick_edit_dropdown_pages_args',...
From the source code the function wp_dropdown_pages uses get_pages() and this function uses different attributes than WP_Query or get_posts(). It uses authors instead of author . Note from the codex: authors (string) Only include the Pages written by the given author(s) Note: get_posts() uses the parameter 'author' ins...
How can I limit page parent dropdown to show only author's own pages?
wordpress
I needed to use the category name as a class for the H1, and also needed to exclude category 2. So I botched together the PHP code below. It works fine except the post looses it's formatting. I know that <code> get_post_format() </code> is what applies the format, but when I add it, it doesn't seem to do anything. Any ...
Ok, try this (untested, so excuse any minor typos/syntax errors). I have amended so that The Loop first checks that there is Posts to show. I've also removed the need for <code> $count </code> and the addition of <code> ' ' </code> by adding any matches to an array, and then outputting them using <code> join() </code> ...
Single.php loses it's formatting
wordpress
I've a query here : <code> $sql = "SELECT ID,post_title,post_content,post_date,post_type FROM {$wpdb-&gt;posts} WHERE post_content LIKE {$stuff} AND post_status = 'publish' AND post_type = '{$post_type}' AND ID != {$post-&gt;ID} LIMIT {$limit}"; $results= $wpdb-&gt;get_results($sql); </code> <code> $stuff </code> is a ...
You have to enclose the OR part to brackets: <code> $sql = "SELECT ID,post_title,post_content,post_date,post_type FROM {$wpdb-&gt;posts} WHERE (post_content LIKE {$stuff}) AND post_status = 'publish' AND post_type = '{$post_type}' AND ID != {$post-&gt;ID} LIMIT {$limit}"; $results= $wpdb-&gt;get_results($sql); </code> ...
Mysql query and odd results
wordpress
I have created a custom post type, but I want to remove the View link from actions, in the listing of the custom post. I have tried this snippet <code> add_filter( 'post_row_actions',array(&amp;$this, 'remove_row_actions', 10, 1)); public function remove_row_actions($action){ unset($action['view']); return $action; } <...
You've got typo in your add_filter. Try this: <code> add_filter( 'post_row_actions',array(&amp;$this, 'remove_row_actions'), 10, 1); public function remove_row_actions($action){ unset($action['view']); return $action; } </code>
wordpress remove views from action links in a custom post
wordpress
So, I'm using a custom post type archive and generating a JavaScript-based filtering interface for sorting through results. Here's an example: http://www.inverity.org/sermons/ Now, what I'd like to do is pass in variables to my script to allow for filtering based on URL parameters. This works: http://www.inverity.org/s...
I had the same problem on my large project that I currently work on. It's case when you have collision between taxonomy and post-type slugs. Problem is that you can filter by taxonomy with adding <code> ?taxonomy_name=term_slug </code> and also you can see the custom post by adding <code> ?post_type=custom_post_slug </...
CPT archive 404ing when using a custom taxonomy name as a variable
wordpress
I am using the All-in-One Event Calendar by Timely, and I would like to display upcoming events from the events calendar in a carousel on a separate page, and I need to get the event information. I am using the ai1ec helpers and get_events_between to get the events within a certain date range (between today and a year ...
Finally have a chance to post my solution. Note that the events show All Day events first if there are any. Unfortunately I don't know a way around this as it is coded this way in a SQL query within one of the plugin files (and it is even commented in the file that All Day events are first). I am also using the event i...
All-in-One Event Calendar: Custom Query - Getting each event Instance
wordpress
I would like to know if it is possible to enable free shipping with Woo Commerce only if certain items (or items of certain categories / shipping classes) are included in the cart. The Free Shipping option only activates on the basis of cart value or via a coupon code so I investigated Flat Rate shipping and discovered...
Perhaps this doesn't fully answer your question, but the table rate shipping plugin does give you the option to set a priority for a particular rate. Furthermore, this discussion gives a lot of hints as to where you could look for solutions
Enabling free shipping on Woo Commerce by specific items
wordpress
QUESTION This is following a previous question that was graciously answered by Milo earlier here - stackexchange-url ("How to sort CPT by custom meta value (date), and return posts month by month") In short, I'm having some issues with properly formatting my custom meta box date's in a few areas... Namely, in the back-...
but when I visit a month with no posts my template returns the date "January 1970" instead. Yes. That will happen. UNIXTIME began on Jan 1, 1970. That is "0000/00/00" but negative numbers work back until sometime in 1901. <code> strtotime </code> will return <code> false </code> for anything outside that range, includi...
Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
wordpress
I want to create an edit media button for my plugin, right now you can easily upload images using the WordPress 3.5 media uploader but I want the user to be able to edit the uploaded images, something like this: Any ideas on how that can be achieved? Here is the code that I am using to open the media uploader right now...
I think you are on the same boat with us: http://wordpress.org/extend/ideas/topic/custom-attachment-type Its not possible easily at the moment. If you and others supports my idea, maybe we will see it for wordpress 3.7
How to create an edit media button for slideshow plugin?
wordpress
I think my problem is partially a javascript problem, but if someone knows of a better way to do this I'd love to hear it. Basically the goal is to "save the client from themselves" by not allowing them to move around certain menu items in the custom menu. For SEO reasons. Whether that makes sense or not is beside the ...
The answer for my situation was, "don't do it this way." I remove the menu item I wanted to hide, which happened to be the "Home" menu item, and just used the default show_home argument on wp_nav_menu to add it in. Kind of silly I didn't realize I could do this before.
How can I disable sorting/dragging of a menu item in the custom menu admin?
wordpress
How to get the meta value by meta key I want to get the value by the meta key. This is what I have tried so far: <code> $args = array( 'post_type' =&gt; 'post', 'post_status' =&gt; 'publish', 'posts_per_page' =&gt; -1, 'meta_key' =&gt; 'picture_upload_1' ); $dbResult = new WP_Query($args); var_dump($dbResult); </code> ...
<code> WP_Query </code> selects posts and not meta value that is way you are not getting the value. You can use the returned post ID to get the value something like: <code> $args = array( 'post_type' =&gt; 'post', 'post_status' =&gt; 'publish', 'posts_per_page' =&gt; 1, 'meta_key' =&gt; 'picture_upload_1' ); $dbResult ...
wordpress get meta value by meta key
wordpress
If I use: <code> add_image_size('main_image', 750, 375, true); </code> to add additional thumbnail size. Then how can i get that size if i have only key <code> main_image </code> .
This is answered here: stackexchange-url ("Get post thumbnail size") <code> global $_wp_additional_image_sizes; // Output width echo $_wp_additional_image_sizes['main_image']['width']; // Output height echo $_wp_additional_image_sizes['main_image']['height']; </code>
Get custom thumbnail sizes
wordpress
I have downloaded the following theme ( http://demo.fabthemes.com/xenastore/ ) and i need a little help amending the index page. At the moment it lists every product that i have created on the front page - what i would like is for it to only display a select few from a a certain "department" (they don't use categories)...
You probably want to amend this line: <code> $wp_query-&gt;query('post_type=product&amp;paged='.$paged); </code> To include some more limitations, like <code> &amp;department=Featured </code> . I'm unaware of your whole project's code structure, so I can't advise exactly what you'd need to put.
Amending PHP for Wordpress Theme
wordpress
I've added a custom filter function for <code> the_posts </code> filter in a plugin. <code> add_filter('the_posts', 'posts_filter'); function posts_filter() { … } </code> This works pretty well in the main loop, that means the posts are filtered in the way I defined in the <code> posts_filter </code> function. But I am...
<code> the_posts </code> does work for all queries including the main query as well as custom queries but doesn't work when using <code> get_posts() </code> . This is because <code> get_posts() </code> automatically suppresses all the filters. If you want to use the filters even when using <code> get_posts </code> , yo...
get_posts() and filters
wordpress
I am having trouble wrapping my head around these two functions. I understand <code> do_action() </code> but I don't see clearly when <code> do_action_ref_array() </code> would be useful. Couldn't we pass an array to <code> do_action() </code> as well?
If you pass an array to <code> do_action_ref_array() </code> , each element’s value of that array will be passed as a separate parameter to the callback. The keys are lost. If you pass an array to <code> do_action() </code> , the complete array will be passed as one single parameter to the callback. The keys stay intac...
Difference between do_action_ref_array() and do_action()
wordpress
I would like to create shortcodes, some tutorials write about to use <code> add_action </code> add_action( 'init', 'register_shortcodes'); but I read tutorials where the author didn't use it, only put add_shortcode('recent-posts', 'recent_posts_function'); to <code> functions.php </code> . Which is the best method, and...
If you take a look at the Codex page about <code> add_shortcode() </code> you won't see anything about the need of an <code> add_action() </code> before you can use <code> add_shortcode() </code> . So, you can just put your <code> add_shortcode() </code> directly into your <code> functions.php </code> . This is what I ...
Why are you using add_action for shortcode?
wordpress
I recently changed the database table prefix from wp_ to something else, for security reasons. Since then, I am unable to reach /wp-admin, instead receiving You do not have sufficient permissions to access this page. I read stackexchange-url ("this question"), and I renamed <code> wp_user_roles </code> to <code> mypref...
Changing the db prefix on a WordPress installation requires more than simply changing the prefix on the tables. There are also options that use the db prefix in the options tables. You'll need to update them as well. Specifically the <code> wp_user_capabilties </code> and the <code> wp_user_level </code> keys in the <c...
Troubleshoot "You do not have sufficient permissions to access this page."
wordpress
So I managed to get the issue of stackexchange-url ("headers working properly") in my theme, but I have a new issue with options though. I have the three following pieces of code that work in the order I paste them: Peice 1 All we do is capture that you hit the reset button, call the reset function, when we come back i...
Maybe a little debugging will help. Try this in your piece no.1 <code> $theme = AisisCore_Factory_Pattern::create('AisisCore_Template_Builder'); if(isset($_POST['aisis_reset'])){ $theme-&gt;reset_theme_options(); } $options = get_option('aisis_reset'); print_r( $options ); //outputs $options value wp_die(); //will halt...
Option does not save or update upon page refresh
wordpress
How can I use <code> add_menu_page() </code> functions some variable function ? <code> add_menu_page('My page','My page','manage_options','my_page', 'func' ); $func = function() { echo "Done !"; }; </code> I know I can use like <code> function func() { echo "Done !"; }; </code> But how can I use like <code> $func = fun...
You have to declare the closure before you call <code> add_menu_page() </code> : <code> $func = function() { echo "Done !"; }; add_menu_page('My page','My page','manage_options','my_page', $func ); </code> Note you need PHP 5.3 to do that.
add_menu_page() with variable function
wordpress
I've been developing plugins for about a year now, but not having any experience with multisite environments, whenever a question comes up that is specific to that environment I'm generally stumped. Today, I got a question regarding Document Gallery . The question states that the user attempted to install the plugin as...
You can use the <code> is_multisite() </code> function to test to see if you're installed in a Multisite-enabled site. That way, if there is any functionality you need to provide specific to a Multisite installation, you can do it like this: <code> if( is_multisite() ) { // special code here } </code> Most plugins that...
Is there anything special required to make a plugin work in a multisite environment?
wordpress
I am looking for the right hook to use for sending out an email notice when a post is inserted. However, I am using custom statuses (in this case 'holding') which doesn't seem to get hit with the new_to_holding hook, so was hoping someone knew of an alternative that gets fired when a post is inserted or perhaps a reaso...
new_to_holding doesn't exist as a post status transition - you need to use the generic transition_post_status action. Something like (untested): <code> add_action('transition_post_status','my_holding_function', 10, 3); function my_holding_function( $new_status, $old_status, $post ) { if ( 'holding' == $new_status ) { /...
Alternative to new_to_publish Hook for Custom Statuses
wordpress
I am a totally fresh with wordpress I have this website : http://www.raminusa.com/ in footer there is a column name "Popular Link" and I want to replace it with Recent News that I will do but below this heading I need my first 5 or 4 recent post from my wordpress blog. My wordpress blog is : http://immigrationstatus.wo...
EDIT After a brief chat with Original Poster, the following solution works: Install the Magpie RSS library . Create a folder in the root directory of <code> raminusa.com </code> , name it magpierss Upload 4 files (*rss_fetch.inc*, *rss_parser.inc*, *rss_cache.inc*, and *rss_utils.inc*), and the directory extlib to this...
Display wordpress post to static website in the footer
wordpress
When I use fetch_feed() to pull in posts from a feed, even if I set the maximum posts variable to a very high number, it will only pull in 10 posts. I want to pull in all the posts and then paginate the way I would for my regular blog posts. I thought maybe it was set to the number in my Reading settings, but I changed...
It sounds like your source feed is showing only 10 posts. So, regardless of what you pit for get_item_quantity, only 10 posts will show, max. If you're pulling posts from a WordPress site, you can adjust how many posts are included in the RSS feed in Settings -> Reading. Change this value: "Syndication feeds show the m...
How do I use fetch_feed() to pull in a large number of posts?
wordpress
Here is my problem: For my articles, I use a custom post type "exhibitions" and posts for all other news. I am displaying them in one query ['post_type' = array('exhibitions','posts')]. The orderby parameter for posts should be their publish date , for exhibitions it should be custom meta value (end date of the project...
To the best of my knowledge, you cannot sort a query by two different parameters without an additional iteration over the retrieved posts. Since that ideally should be avoided, let me suggest a different approach: How about incorporating an additional meta value "sort_date", or the like? And then, in your saving routin...
Wp_query: sort by PHP variable
wordpress
I've done my share of searching, but apparently my search-fu is failing me, because I haven't found anything that really seems to fit my circumstance. Also, I don't want to just try random solutions and end up bricking everything. I have a client who has previously managed her site and installations herself and has now...
Serve both sites from the same installation. In your <code> wp-config.php </code> include the settings depending on <code> $_SERVER['HTTP_HOST'] </code> . Example for a complete <code> wp-config.php </code> : <code> define( 'DB_HOST', 'localhost' ); define( 'DB_CHARSET', 'utf8' ); define( 'DB_COLLATE', 'utf8_general_ci...
Multiple domains for multiple single installs
wordpress
I absolutely hate this error. And do not understand it at all. So this is my code, what you want to focus on is the foreach loop: <code> public function reset_theme_options(){ if($this-&gt;is_theme_options_array()){ foreach($this-&gt;_theme_option['admin_options'] as $option_name=&gt;$value){ if($value != false){ delet...
The actual way to get around this is to put the following in your functions.php file: <code> function callback($buffer){ return $buffer; } function add_ob_start(){ ob_start("callback"); } function flush_ob_end(){ ob_end_flush(); } add_action('init', 'add_ob_start'); add_action('wp_footer', 'flush_ob_end'); </code>
Cannot modify headers
wordpress
Having checked my site with google page speed and gzipwtf.com I have noticed that my css and js files are not getting compressed (although html is). Have tried unchecking " Prevent caching of objects after settings change " and have thus removed query strings from these files but that has had no effect. Have also tried...
Thanks to @Pothi Kalimuthu I checked with my hosting company to see if mod_deflate was enabled, and it wasnt. This was the problem. I mistakingly believed that it was by incorrectly reading the results of phpinfo.
W3 Total Cache CSS & JS files GZip issues
wordpress
How we can get the success messages like we can get the error messages by simple using the variable <code> $error </code> . So there is any other variable like <code> $success </code> . Currently i am using this code to register a new user. so after registeration i want to display success message. <code> if ( 'POST' ==...
You can declare $success variable and use it to display success message as following. Declare $success variable and assign success message to it if user is registered successfully as following : <code> $success = ''; if ( 'POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty( $_POST['action'] ) &amp;&amp; $_POST['acti...
How we get the success messages
wordpress
this page was working initially, and then I made some changes which * didn’t * appear, and then it just stopped showing that page altogether. I have tried deleting my <code> wpsc-single_product.php </code> and replacing it with the default one provided but it still just shows 404. My category page does the same, in fac...
I fixed this in the end. There is a button in the wpsc settings page under presentation to flush the theme cache. Caption: If you have moved your files in some other way i.e FTP, you may need to click the Flush Theme Cache. This will refresh the locations WordPress looks for your templates. Simple, and hard to miss, bu...
wp e-commerce single-product template giving 404
wordpress
There's no mention of custom fields values in Get_post's codex page . Is it impossible to use get_post to get a custom field value of some post, and if so, is it necessary to perform a whole loop just for that?
All of the custom field functions accept the post id as a parameter. You can use all those functions directly without the need to actually retrieve the post itself.
Retrieving custom field value with get_post?
wordpress
I am working with HTML5 Blank and I can't seem to get jquery to stop being called in wp_footer(). I have tried adding this to the bottom of my functions file: <code> function theme_slug_dequeue_footer_jquery() { wp_dequeue_script( 'jquery' ); } add_action( 'wp_footer', 'theme_slug_dequeue_footer_jquery', 11 ); </code> ...
If your working with a blank theme why don't you just remove or comment out the <code> wp_enqueue_script('jquery'); </code> in the theme functions.php? Otherwise your action hook is wrong, use, <code> add_action('wp_print_scripts','theme_slug_dequeue_footer_jquery'); function theme_slug_dequeue_footer_jquery() { wp_deq...
Removing jQuery from footer
wordpress
I have a cron job set to remove a (sometimes large) number of posts from my database. Of course, I also need to remove all associated data such as custom fields. This is the function I'm currently running, but it's taking a bit long to delete everything. Would it maybe be more efficient to make a direct SQL query? <cod...
Yes, but unless you have total understanding of your system and it is going to be frozen at that state, this can be dangerous. Can you be sure that you know all the places in the DB where the post is referenced? There is the post table, the metadata table, taxonomies, and plugins. If you figure it all out, are you sure...
Most efficient way of deleting post
wordpress
I'm occasionally facing this problem and not sure what causes it, any ideas? <code> &lt;?php get_header(); ?&gt; &lt;div class="content" role="main"&gt; &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;?php get_template_part( 'loop', 'index' ); ?&gt; &lt;/div&gt; &lt;?php get_footer(); ?&gt; </code> For a normal pa...
<code> the_title </code> is a Loop tag. It "Displays or returns the title of the current post" and it is supposed to be used inside the Loop, not outside of it. What you are doing-- calling it outside the Loop-- is not quite correct, and you are getting inconsistent results. What happens is this: The <code> $post </cod...
the_title() shows title of the first post instead of the page title?
wordpress
I'm having an issue with pagination. I have a media category, using a category-media.php template. I have a custom loop with a paged variable. There are 30 posts total. Sample: <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' =&gt; 3, 'category_name' =&gt; 'media', ...
WordPress determines if a paginated page exists based on the results of the main query. Each page is actually querying 6 posts, while your custom query only loads 3. The solution - Don't create a new query in the template, use <code> pre_get_posts </code> to modify the main query via your theme's <code> functions.php <...
Wordpress Pagination not displaying posts after certain page
wordpress
I found an <code> $interim_login </code> variable within the <code> wp-login.php </code> file, and I'm not sure what it does or what it is. The documentation around the interwebs is pretty sparse. What is <code> $interim_login </code> ?
The variable <code> $interim_login </code> is <code> TRUE </code> when the log-in session of a user expires while she is working in the back end, for example during an auto-save action. In this case a message asking to log in again appears at the bottom of the editor: The same can happen in the theme customizer. The <c...
What is $interim_login?
wordpress
External rewrite rules are awesome. They let you define rewrites that don't necessarily pass through WordPress' <code> index.php </code> . This means you can map arbitrary rules to arbitrary files like: <code> $wp_rewrite-&gt;add_external_rule( '^somethingrandom/?$', 'wp-content/wp-uploads/hiddendirectory/somefile.php'...
This also assumes .htaccess files are enabled in Apache, which almost always is in shared hosting, but is often disabled in enterprise environments. One way to accomplish this would be to write your own add_external_nginx_rule function that writes redirets out to a file (could use .htaccess even, though that might be c...
How do I add a server-independent external rewrite rule?
wordpress
I'm doing a custom page that has multiple wp query calls, the thing is that I don't need the main query that is I don't need anything from the page contents, so in order to save load time I was wondering how to tell wordpress not to fetch anything from the db ?
I would highly recommend you to make one of those wp query calls the main query &amp; all others as secondary queries. That will make your life much easier in the long run. If you absolutely want to disable the main query, wordpress doesn't have a direct filter for that. You can however do a trick to achieve that 1) ho...
Avoiding page loop
wordpress
I'm using <code> WP_Query() </code> to pull out a few posts under a specific category "Featured" to display at the bottom of any post. So I added <code> &lt;?php if (function_exists('getEditorPicks')) getEditorPicks();?&gt; </code> in single.php. In functions.php, I have <code> wp_reset_postdata(); $args = array('cat' ...
<code> $query-&gt;the_post; </code> should be: <code> $query-&gt;the_post(); </code> The first is trying to fetch a property named <code> the_post </code> rather than invoking the function so the post never advances, and your loop is infinite.
How to use WP_Query() on single.php?
wordpress
In Woocommerce 2.0, I need to print a custom field on the New Order email. It is a meta/custom field each product has named "longsku" (which is normally hidden.) This needs to be included in the email-order-items.php email template but I am not certain what syntax is necessary to print it. For instance, variations are ...
the longsku is regular wordpress post meta, so you can simply call that with get_post_meta . get_post_meta takes three arguments: post_id (which is already available in $_product)] meta key ('longsku' in your case) and a boolean to return a single string (true). if not set, it returns an array, but since the meta key i...
Woocommerce - Print Product's Custom Field In Email
wordpress
Searching for " WordPress Reauth " and the like all result in folks who are having problems with <code> ReAuth=1 </code> . What exactly is ReAuth?
<code> ReAuth=1 </code> is required when your login <code> Cookies </code> are no longer valid, WordPress will force validation for your browser. <code> if ( $force_reauth ) $login_url = add_query_arg('reauth', '1', $login_url); </code> Add reauth=1 flag to login url when auth_redirect() redirects to wp-login.php after...
What exactly is ReAuth?
wordpress
Good day I am using the easy table plugin and I have a problem with floats with it: Any content I add below the table floats to the right of the table. Now I can solve this by using a <code> &lt;div style="clear: both"&gt;&lt;/div&gt; </code> but isn't there a more 'user-friendly' way of doing it? That way my clients (...
You should take a look at the CSS the table uses. Right now it probably uses <code> float:left </code> values. Use Firebug or a similar tool to check if this is the case, and try to edit the CSS.
'Easy Table' Plugin has float issues
wordpress
Is there an easy way of outputting the current pages menu text? I am looking for something like <code> &lt;?php echo get_the_title(); ?&gt; </code> But for the current pages menu text.
You can get a Menu's entire item list with wp_get_nav_menu_items() . Then, loop through them all and test against the current post_id, and voila, you have all your data. <code> &lt;?php $menu_items = wp_get_nav_menu_items( 'main-menu' ); foreach( $menu_items as $item ) { print_r( $item ) ; // see what you can work with...
How to get current pages menu text?
wordpress
I am using wp_list_authors function to list all the users in my blog, however it doesn't display the users who wrote custom post types. it only displays the users who wrote regular posts. Is there a way of displaying all the users who wrote posts and also including the users who wrote custom post types in the same list...
Add the following function in functions.php and use custom_wp_list_authors function in place of wp_list_authors in your theme where you want to display authors who wrote custom post types post. <code> function custom_wp_list_authors($args = '') { global $wpdb; $defaults = array( 'orderby' =&gt; 'name', 'order' =&gt; 'A...
wp_list_authors including custom post types
wordpress
I have a site that will have some custom roles (capabilities), and I would like to have archives that list authors based on their role. authors.php list the profile of one author, but there is no template for listing authors, right? Is a custom template the only way to do this? I would rather not have empty pages that ...
You may be able to abuse <code> add_rewrite_endpoint </code> for this purpose, depending on exactly what you want to do. Some examples: <code> // add an endpoint // http:domain.com/role/ // http:domain.com/role/foo/ function wpa_add_role_endpoint(){ add_rewrite_endpoint( 'role', EP_ALL ); } add_action( 'init', 'wpa_add...
Create archives by author role
wordpress
I'm looking to see if it's possible to find and remove duplicates from the arrays generated below. I've tried <code> array_unique </code> <code> array_merge </code> and they haven't worked. <code> $category = get_the_category(); $tags = wp_get_post_tags($post-&gt;ID); </code> As an example, there is a potential that th...
If you only want to collect the category+tag names into the output, you can try this <code> &lt;?php global $post; $words=array(); $tags = wp_get_post_tags($post-&gt;ID); foreach($tags as $tag){ $words[]="%23".$tag-&gt;name; } $cats = get_the_category($post-&gt;ID); foreach($cats as $cat){ $words[]="%23".$cat-&gt;name;...
Finding and removing duplicates within WP Arrays
wordpress
I want to create a plugin to sanitize comment and mainly the url field before display only (not before adding to database), to filter the url fields and only allow displaying this field only if it contains specific data, otherwise I want to replace this url field with something safe or clear it. ( i do not want users t...
You might want to check out the <code> comments_array </code> filter. In 3.5, it is applied in Line 891 of wp-includes/comment-template.php : <code> $wp_query-&gt;comments = apply_filters( 'comments_array', $comments, $post-&gt;ID ); </code>
Creating a plugin to sanitize comment and the url field before display only
wordpress
I'm going to make a contact form for my site, and i want to use WYSIWYG editor (wp_editor) in my form message field. Here is my question, is that safe use wp_editor in public though disable media button? something like this: http://i.stack.imgur.com/dpspL.jpg Thanks.
It should be fine and secure, as Horttcore mentioned it isn't making any database or backend changes it is simply displaying the tinymce editor. There are other plugins you could use of course but I don't see any problems doing exactly what you are doing. To answer your other question, I believe the text/visual switch ...
Is it safe use wp_editor in public contact form
wordpress
I want all my users (contributors and authors too) but the admin to be redirected to the homepage if they try to view mysite.com/wp-admin/. Contributors and Authors must be able to add and edit posts as usual, along with others they've to be forced to be redirected... I've already removed the link to the dashboard... I...
Unfortunately none of the above codes worked for me as they just redirected non admin to homepage even if I wanted authors and contributors to be able to add/edit and delete their posts... I've ended removing the boxes in the dashboard and I solved (partially) my issue. I added this in functions.php <code> function dis...
How to redirect non admins to homepage if trying to view mysite.com/wp-admin/?
wordpress
One of my clients has decided to install an SSL certificate for his website/domain. I have developed a WP website for them it's ready to be deployed. We are currently accessing it via the IP address and it works fine. Normally I just change the URL settings via admin (2 options) and run a search and replace throughout ...
There is no need to hardcode anything and/or alter database entries. I'd highly recommend you'd check out the following plugin: WordPress HTTPS - it's quite versatile and will handle everything for you.
SSL Certificate and WordPress
wordpress
I have a front-end form which stores some data related to that post and adds that post to their <code> favorite </code> posts when the user clicks on it. So now my concern is when the user clicks on the favorite posts template it should only see their favorite post. <code> $args = array('posts_per_page' =&gt; 20, 'page...
change the $args to this: <code> $args = array( 'posts_per_page' =&gt; 20, 'paged' =&gt; $paged, 'post_type' =&gt; 'post', 'post_status' =&gt; 'publish', 'meta_query' =&gt; array(array('key'=&gt;'favpost'.$userID, value=&gt;'1', 'compare' =&gt; '=')) ); </code> That is if the post_meta value is 1 when the user select t...
Write query according to post_meta
wordpress
Good Day All I have a featured slider on the home page that can call a category from which it gets its featured content. Now, for each featured slider, I made a post with category 'featured'. Now the problem is, that currently when you click on the featured slide, you get directed to its originating post with category ...
try this: <code> &lt;h2 class="featured-title"&gt;&lt;a href="http://siteurl.com/category/&lt;?php echo strtolower(str_replace(" ","",$arr[$i]["title"])); ?&gt;"&gt;&lt;?php echo esc_html($arr[$i]["title"]); ?&gt;&lt;/a&gt;&lt;/h2&gt; </code>
Customizing a permalink
wordpress
I like the idea of enabling any user of my website to suggest edits to a page. Much like the edit system on Stack Exchange but different in that anyone should be able to edit, not just registered users. All edits would go through an approval process. How could I implement that?
Diff the post content, title and author As had to do something related some month ago, here's the easiest and most future proof way (that I could fine) to check if there's a change made to the content or title or if the author changed: <code> // Update Title '' !== wp_text_diff( $el['post_title'], $GLOBALS['post']-&gt;...
How to enable suggested edits?
wordpress
I am trying to use the total posts count currently i am using the this query <code> $args=array( 'author' =&gt; $userID, 'post_type' =&gt; 'post', 'post_status' =&gt; $poststatus, 'posts_per_page' =&gt; 212 ); &lt;?php echo count_user_posts($args); ?&gt; </code> <code> $poststatus </code> have 2 options <code> draft </...
The function <code> count_user_posts </code> only accepts a user ID so you arguments are never taken in consideration. Here is a simple function to get the count by status <code> function count_user_posts_by_status($post_status = 'publish',$user_id = 0){ global $wpdb; $count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( " SE...
How we count the user draft posts
wordpress
I'm working on a plugin and want to restrict some things to my plugin-specific admin menu pages only. Therefore, I write the slugs being returned when adding (sub)menu pages into an array so I can check later on the current page against it. The problem seems to be that <code> get_current_screen </code> is returning <co...
The slug returned by <code> add_menu_page() </code> is the name of an action. <code> foreach ( $menu_pages as $action ) add_action( $action, "callback_handler" ); </code> See the comments in my demo plugin T5 Admin Menu Demo .
Restrict certain actions to plugin-specific admin menu pages only
wordpress
<code> &lt;h1&gt;&lt;?php the_category(' &amp;bull; '); ?&gt; » &lt;a href="&lt;?php the_permalink(); ?&gt;" class="my-title-class"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt; </code> How to add <code> class="my-category-class" </code> to the links, produces by <code> the_category </code> function?
You can use <code> the_category </code> filter to hook a callback function like this: <code> add_filter('the_category','add_class_to_category',10,3); function add_class_to_category( $thelist, $separator, $parents){ $class_to_add = 'my-category-class'; return str_replace('&lt;a href="', 'class="'. $class_to_add. '" &lt;...
How to add style to category link?
wordpress
Does someone know if it's possible to display a specific sidebar per user-role ? (only accessible if the user is logged as the specific role related to the specific sidebar )? What I want is to have one "profile-like" page in the front end with a custom sidebar per role (with custom nav, custom content, custom links......
You could either read the role of the current user, then show the desired sidebar elements, or (what I'd prefer) check for certain capabilities. User Role <code> global $current_user; $roles = $current_user-&gt;roles; $role = array_shift( $roles ); switch ( $role ) { case ... } </code> Capabilities <code> if ( current_...
display specific sidebar for each role
wordpress
When is it appropriate to remove a plugin's settings? On deactivation or uninstall?
Remove data only on uninstall. Deactivating plugins can be done by mistake or in order to troubleshot some other problem and you don't want to make the plugin users to config everything again in this situation. Think about your PC software, does it delete its data when it is being closed and become inactive? no, only w...
Best Practice: Remove data on deactivation or uninstall?
wordpress
This is what in my wp-config.php : <code> if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); </code> I am calling from plugin/pluginName directory to : <code> require_once( ABSPATH . 'wp-includes/user.php'); </code> But it is returning: <code> Warning: require_once(ABSPATHwp-includes/user.php) [func...
If you just need that class included, and your script is located in the plugin directory, like <code> /wp-content/plugins/pluginName/script.php </code> , then you can do: <code> require realpath('../../../wp-includes/class-phpass.php'); </code>
ABSPATH not working! Any idea why?
wordpress
In my WordPress site, I made a custom page template, which contained a custom query [using <code> WP_Query() </code> ]. With that query, I can perfectly get the posts of a certain category. But I want to show the page contents along with the queried posts. Thing will be like: --------------------------- Page Heading pa...
I'm using two loops. First loop is to show the page content, and the second loop is to show the queried post contents. I commented into the codes where necessary. I emphasized into the loops, as Deckster0 said in WordPress support that, <code> the_content() </code> works only inside a WordPress Loop. I'm placing these ...
How to display page content in a page template?
wordpress
I'm making a child theme for TwentyTwelve, but my host is caching my files, so I'm not seeing the changes I do to my style.css file. Is there a way to version the stylesheet for my child theme? How is TwentyTwelve even adding the stylesheet? I don't see it in header.php. Thanks
How it's NOT done in WordPress The following example is the opposite of how one should do it. Bad practice following: <code> &lt;style type="text/css"&gt; &lt;!-- /* ... Definitions that are hard to override or get rid off are here ... */ --&gt; &lt;/style&gt; </code> This is another example how you should not do it: <...
TwentyTwelve versioning
wordpress
How can i allow users to login to my wordpress site using both email id and username? Currently it is allowing only username.
Here you got a small plugin. If you don't (or can't) use a plugin, this should - in theory - as well work from within your <code> functions.php </code> file. Just leave the plugin comment header out. <code> &lt;?php /** Plugin Name: (#90328) Login with E-Mail address */ function login_with_email_address( $username ) { ...
Email address or username used to login in wordpress
wordpress
<code> while (have_posts()) : the_post(); //some html &lt;li class="icon-date"&gt;&lt;?php the_date('Y-m-d');?&gt;&lt;/li&gt; &lt;li class="icon-time"&gt;&lt;?php the_date('H:i:s');?&gt;&lt;/li&gt; </code> With this code i am getting only date for first post - what is wrong?
I ran into the same problem several times, following changes worked for me in the past: <code> while (have_posts()) : the_post(); //some html &lt;li class="icon-date"&gt;&lt;?php echo get_the_date( 'Y-m-d' ); ?&gt;&lt;/li&gt; &lt;li class="icon-time"&gt;&lt;?php the_time( 'H:i:s' ); ?&gt;&lt;/li&gt; </code> Instead of ...
How to get date for each post?
wordpress
I want to call a function, whenever any user update their profile. How to do that?
It seems as if the hook <code> personal_options_update </code> might be what you're looking for. <code> add_action( 'personal_options_update', 'my_custom_func' ); function my_custom_func( $user_id /* if you need that */ ) { ... } </code>
How to do an event when any user updates their profile?
wordpress
Can I change the default wordpress password hashing system by overriding the wp_hash_password function from plugin? If yes, then what will happen to old stored passwords in DB? How will they be validated for login?
Just figured it out. So thought to leave the solution here, if someone else need it: To change the default hashing system, need to overwrite wp_hash_password() function: (can be done in a plugin) <code> if ( !function_exists('wp_hash_password') ){ function wp_hash_password($password) { //apply your own hashing structur...
How can I change the default wordpress password hashing system to something custom?
wordpress
I would like to be able to add a class such as <code> .samedate </code> to posts that share the same <code> meta_value_num </code> from a custom meta box. So for example: Say two posts share the same custom meta box value for a date entered as <code> 2013/11/03 </code> ... If those two posts have the same meta value nu...
<code> add_filter('post_class', function($classes){ global $wp_query; static $meta = array(); // first call gathers meta values if(!$meta) foreach($wp_query-&gt;posts as $post) $meta[$post-&gt;ID] = get_post_meta($post-&gt;ID, 'your_meta_key', true); // $wp_query-&gt;post should be the global (current) $post object $th...
Add a class to post_class if more than one post shares same meta_value_num
wordpress
I'm trying to use an ajax function in my custom template to retrieve a post's custom fields to show a post overview. Getting the custom fields is working, but the getting the permalink isn't. I'm getting the permalink so I can link to the post. All I get back when I use <code> get_permalink() </code> is the first lette...
The value of index 'link' of the array <code> $plane_details </code> is a string, and thus <code> $value[0] </code> gives you the first letter only. Just replace <code> $value[0] </code> by <code> $value </code> and all should be fine. Why are you referencing the value this way, anyway?
get_permalink returning first letter
wordpress
With a plugin, I have used require_once in the init.php of a plugin that I have made for my site to make functions available. With a child theme, where should I put the calls to require_once? When I put them into the template file that uses it, it doesn't seem to work. EDIT I would have thought that this <code> locate_...
When you create a theme, you can use <code> functions.php </code> file for all utilize functions. Also this is the best place for all your <code> require_once </code> calls. One trick I would like to recommend for theme development approach: Don't use direct <code> require_one </code> call to include your scripts. Inst...
Utilize Function in Child Theme / Template File
wordpress
I have a 2GB WordPress database (using InnoDB Storage Engine) and I noticed my site loads slow when I press the publish button right after I selected a featured image in the media library. I had a look at my tables and noticed <code> wp_postmeta </code> is the biggest table and <code> wp_posts </code> the 2nd biggest o...
DISCLAIMER : Not a WordPress Developer, Just a MySQL DBA There is a special table structure in Oracle called a Materialized View. Basically, it is built by performing a JOIN query (using no WHERE clause) and storing the result set. Then, simply SELECT from that static result set rather than rebuilding each JOIN result....
Large database causes slow load
wordpress
My default wordpress set hold 10 posts per page. In category.php , I want to override this with 999 post per page, the problem is that isn't working at all. When I use the following code. it doesn't adjust alphabetically or shows 999 posts <code> &lt;?php get_header(); ?&gt; &lt;section id="index" class="index"&gt; &lt...
The issue with your query is that <code> new WP_Query($query_string,$args); </code> is not correct syntax, however, creating a new <code> WP_Query </code> is not the way to do what you want. See the codex page for <code> pre_get_posts </code> for the correct way to modify the main query. I assume by setting posts per p...
new WP_Query issues
wordpress
i'm new to creating wordpress themes and want a menu at the Top of my page. I do have the following: Header.php <code> &lt;html&gt; &lt;head&gt; &lt;title&gt;Tutorial theme&lt;/title&gt; &lt;link rel="stylesheet" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;"&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrapper"&gt; &...
In my opinion, this is a CSS-only question. You have to provide the <code> &lt;li&gt; </code> elements in your menu with the CSS style <code> display: inline; </code> (or 'inline-block').
Creating a Horizontal menu
wordpress
I need a way to change the encoding type for my comment form, without hacking the core files. I'm aware of the function to work on the post editing form: <code> post_edit_form_tag </code> . I've tried this: <code> jQuery('#comment_form').attr("enctype","multipart/form-data"); </code> But it doesn't work, the only next ...
One Trick Pony answered the question, here's his solution: <code> jQuery('#comment_form')[0].encoding = 'multipart/form-data'; </code> And here's a jsFiddle of it.
How to add enctype to multipart/form-data to comment form?
wordpress
Savvy WordPress user here, or at least trying to be. I have the hang of hooks and filters with the code in WP's plugin.php The only thing I cannot seem to understand is the $merged_filters global. The value for a tag is unset when a filter or action is added. However, when an action or filter is executed, the $merged_f...
For those of you who may be wondering what this does - I have figured it out. When a new function is added to an action/filter hook, it is added at the end of the array. However, WordPress specifies that those functions are to be executed by priority. When a function is added, merged_filters is used to keep track of wh...
What is the purpose of $merged_filters?
wordpress
I am trying to make widgets accept php, but without resorting to plugins. So far I have enabled php for the widget_text but cant make it work for widget_title. I am using the following code in functions.php: <code> add_filter('widget_text','execute_php',100); function execute_php($html){ if(strpos($html,"&lt;"."?php")!...
You can use the filter <code> widget_title </code> and a "virtual" shortcode. Of course, as stackexchange-url ("One Trick Pony") points out, the "why" (and the "what") is essential to find a proper solution... Supposing the widget title was <code> Title [php] More Title </code> : <code> add_filter( 'widget_title', 'pse...
How to make widget title accept php?
wordpress
I am using an <code> onclick </code> function to redirect the user if they are not login. I am calling a php function in achor tag like this <code> &lt;a href="#" class="fright hrtacnhor" onclick="&lt;?php checkstatus(); ?&gt;"&gt;save to my favorite&lt;/a&gt; </code> and the function I am using is <code> &lt;?php func...
You could do the redirect by means of JavaScript: <code> &lt;a href="#" class="fright hrtacnhor" onclick="window.location='&lt;?php echo get_permalink( 8 ) ?&gt;'"&gt;save to my favorite&lt;/a&gt; </code> But why yould you want to do it that way and not just use the link directly?
How we redirect to other pages in WordPress?
wordpress
When a plugin is being updated via the automatic updater, is that plugin deactivated and then re activated when the plugin update is finished? Also is a maintenance file created during theme and plugin updates, or only during core updates?
According to the source code of wp-admin/includes/class-wp-upgrader.php Single plugin update: <code> add_filter('upgrader_pre_install', array(&amp;$this, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array(&amp;$this, 'delete_old_plugin'), 10, 4); </code> It'll deactivate the plu...
Plugin update, is a deactivation and activation done?
wordpress
I'm working on a site for a client who is using version 2.0.1 of WooCommerce plugin and I'm lost as to how I can create new page templates for it. With previous versions of the plugin is was simple, you just copied files from the "templates" folder into your theme folder and boom! But now, that folder is gone. The WooT...
Actually, the templates folder is still included in WooCommerce, just like before. Just copy its contents to yourtheme/woocommerce and, hey presto, it works! N.B. This doesn't work when you use the woocommerce_content() function in a woocommerce.php. WooThemes actually have a good primer page that they even link from a...
How to create custom WooCommerce 2.0 templates
wordpress
I've previously used WAMP for developing WordPress themes locally using a WordPress Network using sub domains. Having to set it all up again every time I want to develop on a new computer is a pain, so I decided i wanted to do a portable installation, this way the only file I have to change when using a different compu...
The solution: I pasted the block of Mutisite code below the "That's all, stop editing! Happy blogging." line. I'd installed multisite so often that I didn't pay attention to that part. So if you ever think you've installed multisite correctly but the My Sites button never appears, you've pasted the definitions too far ...
Set up Network Locally on a Flash Drive
wordpress
I know this question might be too broad, but I'm looking for a bit of direction. My client has a woocommerce store with 30-40 products. For whatever reason they do not want to sell online anymore, but they want to retain the product pages, information, etc. on their website. Is there a way, using hooks or otherwise, to...
luckily woocommerce has many hooks, this removes prices and buttons: <code> remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); remove_action( 'woocommerce_single_product_summary', '...
Hide prices and checkout functionality in woocommerce
wordpress
I've written a simple bit of code (cobbled together from various tutorials around the web) that creates a simple meta-box (called 'Subheading') and removes the custom fields from the admin area. It all works fine - until I place the code inside a class. Once I do this, the meta-box stops saving to the database. I suspe...
Enable the magic method __construct You have to change the following line <code> $MySubBoxClass = new MySubBoxClass; </code> Into <code> $MySubBoxClass = new MySubBoxClass(); </code> This way the <code> __construct() </code> magic method will be used. The <code> add_action </code> methods aren't called now. Error in <c...
Plugin code will not work properly inside a class
wordpress
Supposed the specified category name is "product", which has three layered sub-categories. The structure is like the following: product one product two product three product four I want to output all the subcategory names in the <code> sidebar.php </code> of my theme. How do I do? in my theme index.php i using: <code> ...
Please have a look at <code> wp_list_categories </code> , which is all you need. Just choose the arguments to your liking and place the code in your sidebar. Suppose, the ID of your 'product' category is 666, then the basic code could look like the following: <code> &lt;ul&gt; &lt;?php wp_list_categories( 'child_of=666...
how to get all the child category name in a specified category name?
wordpress
I am creating a plugin for a restaurant theme that will provide a few options to add the restaurant hours of operation. Currently, I use a custom post type to control the restaurant hours but have since realized this is a bad practice because if the theme changes that info will be lost. I would like to separate them vi...
I am reading your question as being "Is there a standard practice for where the options menu page should be placed?" Is there a standard practice for where the options should be placed? I don't think so but there are better and worse places. Theme customizer page? No. This is bad for the same reason you are worried abo...
Creating a plugin that will add options. Where should the options menu pages go?
wordpress
I have a menu like: <code> -Item1 --Sub1 --Sub2 --Sub3 --Sub4 --Sub5 --Sub6 -Item2 -Item3 </code> and want to do some costum stuff after x subitems, so I have to determine when x is reached. I tried to define a variable in my costum class and then increment it in end_el(): <code> class Walker_Nav_Menu_Costum extends Wa...
Inside the function your <code> $x </code> is local. You might want to use a static variable: <code> class Walker_Nav_Menu_Costum extends Walker_Nav_Menu { static $x = 0; function end_el( &amp;$output, $item, $depth = 0, $args = array() ) { if ( 1 == $depth ) self::$x++; $output .= "&lt;!-- x:".self::$x."--&gt;"; $outp...
Costum walker with sub menu item count
wordpress
I have a custom post type of 'films', and I'm creating a number of search filters using wp_query. All are working fine, but I now need to add in an option of exclude results that dont have any top level comments. I was hoping it would be as simple as: <code> $args = array( 'post_type' =&gt; 'films', 'comment_parent' =&...
A post without a top level comment means it doesn't have any comments at all. You can't query posts without comments unless you have a custom <code> $wpdb </code> query. You can however run a check against the post to see if it has comments and then display it using <code> has_comments() </code> if the $wp_query object...
wp_query and comment_parent - select only posts with top level comments
wordpress
I'm using TinyMCE Advanced and SyntaxHighliter plugins on my WordPress install. Why does the editor change my inserted code, from: <code> [php] &lt;?php /** echo('code'); /**/ [/php] </code> to: <code> [php] &lt;!--?php &lt;br ?--&gt;/** echo('code'); /**/ [/php] </code>
I suggest you to use <code> htmlspecialchars() </code> before sending content and <code> htmlspecialchars_decode() </code> before showing content on page, here is functions that you need to copy/paste to your functions.php : <code> function wp_po9568($content) { return htmlspecialchars($content); } add_filter('content_...
Why Editor reformats my code
wordpress
i read alot of atricles taking about this but i could fix my problem yet .. i want to make the permlink custom /%category%/%postname% and i searched for the .htaccess in the wordpress files and i couldn't find it so i created one and added this code <code> # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine ...
If your Wordpress installation is in the folder 'sitename', than this .htaccess should go in that folder. Not your theme folder. From the Wordpress codex: WordPress's index.php and .htaccess files should be together in the directory indicated by the Site address (URL) setting on your General Options page ( http://codex...
custom permlink .htaccess file 404 Not Found error
wordpress
I have developed some calculators (in php) for my website and I need Wordpress integration. The calculators have a form and, after submission, the result is shown. The result depends on a query in the database. Is it possible to create "static pages" (at least static URLs) that provide to the user dynamic content? Just...
You do want static pages. The easiest way to do this, and a very good way even if perhaps not the only way, is: Create one or more custom template files for your static pages. This is where your PHP comes in. <code> /* Template Name: Calculator */ get_header(); // your calculator code // Whatever PHP you have should wo...
Dynamic content in a static page
wordpress
I am new to Wordpress but forced to create a website as a Wordpress template for my current employee (I am a front end developer, mostly build new systems/apps etc from scratch). Creating the template is no issue, but how do I go about making everything fully editable? For example the footer: it contains contact inform...
Another option is to create a new post type called "modules" or something to that effect. Then you can create as many of those as you like, for example, "Footer: Contact Information," "Footer: Social Media," "Header: Callout," etc, and you can use that post's ID to bring it into the designated spots in your template. W...
Contact information footer
wordpress
I programmed a theme post (edit: probably that's the <code> single.php </code> template) which uses the function <code> get_userdata( $_GET['p'] ) </code> . But the main admin reformatted urls to this: <code> ~/author/gamelaster </code> (default is <code> ?author=1 </code> ) and now this is not working correctly. How d...
If you are on an "Author" page, and since you mentioned <code> author.php </code> it seems that you are, <code> get_queried_object() </code> will give you the author data, which it seems is what you want. Try: <code> var_dump(get_queried_object()); </code> I believe that is all the information you need.
Theme URLs problem
wordpress
I have built my own theme, which integrates quite well with WooCommerce, but I want to know how to properly get rid of the notification on top of my theme that said my theme didn't support WooCommerce / properly declare support (going a bit further than just clicking away the message).
Digging into the code that generates the notification ( <code> current_theme_supports('woocommerce') </code> ) gives the answer: place <code> add_theme_support( 'woocommerce' ); </code> in your functions.php simple!
How to declare WooCommerce support in your theme
wordpress