question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I have a CPT to replace my "post"-post-type, but I still need to be able to use attachments. The problem is, that attachments have the post-capabilities. I don’t want to give post capabilities to my role, because of that, I tried to find a way to avoid it. I found a hack in the wordpress track: http://core.trac.wordpre...
I solved it. The problem was, that I called the function inside of another function, called later. The snippet in the question works like it should. I thought about deleting the question, but I think for other users, that are searching for a way to do something like that, the snippet would be interesting.
How to let a role handle media without post permissions
wordpress
is there a way to shorten the length of the 'auto generated password' which is sent during registration of a new user? I would like to shorten this password to 5 characters max and also remove the numbers '0' and '1' as they can be confused for letters 'O' and 'L'. My users are not very tech savvy and most don't know h...
Use the <code> random_password </code> hook. It will trigger on new registrations once a random password has been generated. <code> add_filter('random_password', 'modify_the_pass'); function modify_the_pass($pass) { $pass = substr($pass, 0, 6); // make $pass six characters return $pass; // return our new $pass } </code...
How to shorten length of auto generated password sent during registration?
wordpress
I'm trying to perform a dynamic query that uses a dynamically passed taxonomy and post_type, and displays results accordingly — A user makes a selection from 3 drop-downs on a form, each have a value. This is passed by the URL Query string. The query on page picks up parameters from the URL, utilising <code> $_GET </co...
<code> tax_query </code> takes an array of arrays. You have an array of arrays of arrays. <code> var_dump($tax_queries); </code> and will get this: <code> array(1) { [0]=&gt; array(1) { [0]=&gt; array(3) { ["taxonomy"]=&gt; string(15) "difficulty_mode" ["terms"]=&gt; NULL ["field"]=&gt; string(4) "slug" } } } </code> T...
When tax_query used, results disappear (0 =1 produced)
wordpress
I am trying to get the post id by the navigation id to use in a loop. I made a new query to get posts. I am using multiple queries on a page because I need to. one of the queries gets page templates that have categories that you make a post to and it gets displayed by that template. My problem is that if I put in the q...
I think you need to loop the <code> $menu_items </code> because the function, according to the Codex, returns a array. Remplace <code> echo $menu_items-&gt;ID; </code> with <code> foreach ( $menu_items as $menu_item ) { echo $menu_item-&gt;ID; } </code> I need to check the array exactly, but if you need to compare a po...
get post by nav id
wordpress
I'd like to export my database to XML because the import script to my new blog already supports getting data from that. A database backup or wordpress clone is not that useful in this case. The problem is that using the builtin export button times out after 90 seconds. I have ssh access to the server and am not afraid ...
You guys give up too easily :) This worked for me: <code> &lt;?php require(dirname(dirname(__FILE__)) . '/wp-load.php'); require(ABSPATH . 'wp-admin/includes/admin.php'); require('includes/export.php'); ob_start(); export_wp(); $xml = ob_get_clean(); file_put_contents('out.xml', $xml); echo "done" ?&gt; </code>
How can I get an XML export of my 1K+ posts WordPress instance?
wordpress
I'm trying to only display posts with the tags <code> Movie Trailers </code> and <code> Gaming Trailers </code> but my loops are still displaying everything under the category /videos/ heres what I have category-videos.php: <code> &lt;?php if ( have_posts() ) : ?&gt; &lt;?php ?&gt; &lt;?php add_action( 'pre_get_posts',...
In your template, the <code> add_action </code> you have there is way too late because by the time WordPress gets to your template, the query has already been performed. If this is for a category page, I'd do the following in your <code> functions.php </code> : <code> //Display Gaming Trailers function display_gaming_t...
Display Posts Only with Specific Tag
wordpress
I am trying to build a plugin for showing a pie diagram based on the number of those categories which have maximum posts. This diagram is a meta box in post editing page. Here is my source of inspiration: jquery charts Most of the way the function works is same but I added some hooks to add it into meta box. Here is my...
The problem might be because of this line: <code> echo do_shortcode('[mycategories]'); </code> It should not stand alone like this in the plugin file, because this will show up before the headers are sent out. I guess you added this line just to check the output? Try to remove this line or encapsulate it with a relevan...
Category pie diagram meta box in post editing page
wordpress
I am trying to make the thumbnail for each post display on the homepage of a site for a client; although the thumbnails do display, they're not being displayed inside of a specified "thumbnail" div and i cannot figure out why. You can see the issue yourself here; http://roswell.n8geeks.com . As you can see, the thumbna...
<code> the_post_thumbnail() </code> prints the HTML immediately. Use <code> get_the_post_thumbnail() </code> instead to get the HTML into your string. <code> $content .= '&lt;div class="thumbnail"&gt;' . get_the_post_thumbnail( null, "home-post-thumbnail") . '&lt;/div&gt;'; </code>
the_post_thumbnail issues
wordpress
I'm sure this is a simple oversight but I cannot seem to narrow it down: <code> global $wpdb; $tablename = $wpdb-&gt;prefix . "icrm_folders"; $sql = $wpdb-&gt;prepare( "SELECT * FROM %s", $tablename ); //$sql results in SELECT * FROM 'wp_icrm_folders' $result = $wpdb-&gt;get_results( $sql ); </code> This seems to resul...
Don't use <code> $wpdb-&gt;prepare </code> with table names. <code> prepare </code> will quote your table names that will result in incorrect SQL. It is unnecessary overhead as well. Your table name should never, and in your case isn't, be user-supplied data. You have no need to escape it. 'prepare' is for use on user-...
Really simple query giving error in SQL syntax
wordpress
I thought I was making headway in my WordPress Development education until I ran across the Boilerplate for WordPress plugins and it uses a class object. I'm fine with that and understand those concepts and I am a .Net developer. But, for some reason, I cannot get any callback to function properly. All I want at this p...
The callback you have given in <code> add_menu_page() </code> is a static function, not a class method. It should be: <code> add_menu_page( 'School Manager Settings', 'School Manager', 'administrator', 'school-manager-settings', array ( $this, 'show_admin_settings_page' ) ); </code> And please don't use <code> &amp;$th...
Add Admin Menu Inside Construct or Init
wordpress
First, I have a static page for homepage and for blog page too. I created a custom box for pages to setup unique background image for the pages. My idea is working on all page templates, but on blog page something wrong. header.php is same on all page <code> &lt;head&gt; {...} &lt;?php $values = get_post_custom( $post-...
The basic problem is that there is no variable <code> $post </code> in your <code> header.php </code> . That variable might exist in the global scope , but your code operates in a function scope of <code> load_template() </code> which was called by <code> get_header() </code> . So you have four options: Import the glob...
How to use get_post_custom function on the blog page?
wordpress
I am using this get_posts array to retrieve top 15 popular posts by comments. The problem is that it shows those all those highly commented posts from the day posts were added into blog. So, the list sometimes changes but most of the time remains same. How can I limit/show posts of the last 7 days? This would show most...
Here is a function which show the posts of last 7days or you can change it according to your requirement. <code> function filter_where($where = '') { //posts in the last 7 days $where .= " AND post_date &gt; '" . date('Y-m-d', strtotime('-7 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); </co...
Limit popular posts by days
wordpress
We have added a custom rewrite_rule to our site to allow for a pretty inbound link to be parsed and handled properly. Links are constructed as <code> domain.com/meetings/faculty/someIDnumber </code> <code> add_action( "init", "pleasing_permalinks" ); function pleasing_permalinks() { add_rewrite_tag( '%hash%', '([^&amp;...
If <code> faculty </code> is a child page of <code> meetings </code> , the rule should be: <code> add_rewrite_rule( 'meetings/faculty/([^/]+)/?$', 'index.php?pagename=meetings/faculty&amp;hash=$matches[1]', 'top' ); </code> <code> pagename=meetings/faculty </code> instead of <code> p=1598 </code> EDIT- or alternately: ...
rewrite_rule() not preserving the query string
wordpress
I'm trying to cut down on the amount of code that is in my theme options function. I'm adding my settings like so: add_settings_field($k,$v,$callback,$the_options,$the_group,$args); This works for me in every way as long as I write out the name of the function. For example, if $callback = 'awesome_callback' - and I cre...
Do not use different callbacks, use the the sixth parameter for <code> add_settings_field() </code> instead. That is an array, and you can pass any data to the callback here. Example: <code> foreach( $theOptions as $k =&gt; $v ) { add_settings_field( $k, $v, 'my_callback', $the_options, $the_group, array ( 'special' =&...
How can one utilize a variable as a callback function name for add_settings_field
wordpress
Does it make sense to use a nonce on an AJAX action that only returns data and doesn't alter data on the server side? I understand they are important if you are saving data or changing something on the server but if you are just receiving data like a post or metadata, is a nonce really needed?
No, it is not needed. If you want to show the data to some users only, you can use <code> current_user_can( 'some_capability' ) </code> to restrict the access.
Using Nonces for AJAX that only retrieves data
wordpress
I'm trying to install a wordpress installation where the DB will sit on a MySQL cluster (Galera/Percona XtraDB Cluster) and connected through HAProxy. Everything outside of the Wordpress install seems to work fine. Using the mysql client to connect to the database with a username and password works just fine. The Wordp...
SELinux was contributing to the problem. The main issue was that an HTML page was attempting to talk to another port on the localhost. I would not have seen the problem if the HAProxy was running on a separate host. The log was revealed in /var/log/messages, where I should have checked but did not considering I didn't ...
Running Wordpress from MySQL Cluster with HAPRoxy
wordpress
I've download a theme called Contango from Wordpress Themes Repository. The theme have a folder called "languagues" and have a file called "contango.po". I could open that file and do translation, but nothing changed. How could I translate this theme into my own language? Thanks so much and apologize for my newbie ques...
Translation files must be named {locale}.po (e.g. <code> en_US.po </code> in order to be recognized. Rename your language translation file accordingly. See more in the Codex: i18n for developers .
Theme Translation?
wordpress
If anyone can help that'd be great. I've found a snippet of code that I've used which is pretty much doing what I want it to do, which lists out subpages of the parent, adds a thumbnail if there is one, and added a custom excerpt. However, the problem is that I can't add individual <code> &lt;?php post_class(); ?&gt; <...
I'm fairly certain the problem is that some template tags rely on the global <code> $post </code> variable. Using <code> setup_postdata() </code> as you are now, will not alter <code> $post </code> . If you replace all the instances of <code> $pageChild </code> with <code> $post </code> , everything should work. Howeve...
Child Pages Loop
wordpress
I am setting up a small dummy content plugin. What I would like to do is import several posts using <code> wp_insert_post </code> . Then I would like to import several images using <code> wp_insert_attachment </code> and then follow this by setting these imported images as post thumbnails for the various posts that wer...
wp_insert_post() return the ID of the post if the post is successfully added to the database. Save this ID in variable, and than create foreach images if you want to attach the same images for each post. Try something like this: http://pastebin.com/kGu4ZpBi
Import Dummy Content and Post Thumbnails
wordpress
I need to delete old edits and autosave, they have grown overtime, and are not needed anymore, seeing this post: stackexchange-url ("stackexchange-url it states: If you have no use for the post revisions and autosaves then disable them in wp-config and WordPress will clean them up on its own but I can't find exactly wh...
You'll need to edit <code> wp-config.php </code> . To set posts to retain a set number of revisions: <code> define('WP_POST_REVISIONS', 3); </code> To disable post revisions completely: <code> define('WP_POST_REVISIONS', false ); </code>
How to delete old posts' edits to save space?
wordpress
WordPress says that plugins are manually reviewed within a "vaguely defined amount of time". What's the experience? How long does this take, on average?
This appears to be a few days to a week, as said in the comments. I can say I've experienced the same amount of time a few times now. However, this is no rule .
How long does plugin review usually take?
wordpress
I have a Wordpress website that written by third party web developer for version 2.9 before custom taxonomies were fully implemented. We have since upgraded to latest wordpress version 3.5.x. There is a SQL Select query that is generating a bunch of errors in the Wordpress error.log file. In this template, we have a fe...
You should not use a direct SQL query, instead try the <code> WP_Query </code> tax queries e.g.: <code> $args = array( 'post_type' =&gt; 'post', 'tax_query' =&gt; array( 'relation' =&gt; 'AND', array( 'taxonomy' =&gt; 'category', 'field' =&gt; 'id', 'terms' =&gt; array( 22 ) ), array( 'taxonomy' =&gt; 'job', 'field' =&...
How to update Wordpress custom SQL Select query for custom taxonomies so that syntax is correct?
wordpress
Previously, I used the <code> get_option() </code> function to get an option in PHP, like this: <code> $width = get_option('my_width'); </code> This is inside a shortcode function. Now, I want to have an option in JavaScript. Is that possible? The JS is added with <code> wp_enqueue_script </code> , from a shortcode fun...
Define an array of parameters to be injected into the script: <code> $script_params = array( 'myWidth' =&gt; get_option('my_width') ); </code> Localize the script via <code> wp_localize_script </code> : <code> wp_localize_script( 'your-script-handle', 'scriptParams', $script_params ); </code> <code> scriptParams </code...
Using get_option() in JavaScript
wordpress
I have a contact form built with Contact Form 7. What I want to do is when the user hits the submit button to throw up a pop up window with a notice asking if their sure they want to submit the form with an ok or cancel button. I've found the hook 'wpcf7_before_send_mail'. I was hoping there might be something i could ...
The <code> wpcf7_before_send_mail </code> is a hook that is triggered after form submission, so it isn't what you're looking for. You should make a javascript script that triggers when the user hits the submit button on your page. It's implementation could be a simple using javascript <code> confirm() </code> - example...
Are you sure popup on Contact Form 7
wordpress
I'm checking if the next post is available in the same category. If it is, output the link. If it's not, output a static text. I have created a function for this: <code> function thelink() { $next_link = next_post_link('%link', 'Next &amp;rarr;', TRUE); if($next_link){ echo $next_link; } else{ echo 'Next &amp;rarr;'; }...
The problem is that <code> next_post_link </code> actually prints the link. If you want to do this as described above, you could use output buffering: <code> function thelink() { ob_start(); next_post_link('%link', 'Next &amp;rarr;', TRUE); $next_link = ob_get_clean(); if ($next_link) echo $next_link; else echo 'Next &...
Check if next post is available and output a link
wordpress
I want to create a post type but don't allow to create new item on the back-end, the item of this post type can be only created on the front-end by the user. How can I do this? Thank you
You can set <code> show_ui </code> to <code> false </code> in register_post_type arguments You can create a "post" in the front-end using wp_insert_post
how to create a post type like comments
wordpress
I read a tutorial about metaboxes, most of things are clear but I have a question about multiple metaboxes. My question is about saving, in the tutorial: <code> &lt;?php add_action( 'save_post', 'cd_meta_box_save' ); function cd_meta_box_save( $post_id ) { // Bail if we're doing an auto save if( defined( 'DOING_AUTOSAV...
You can use one save function. wp_nonce_field function creates hidden field with action. You can use wp_nonce_field for two metaboxes if you want different actions for two metaboxes. Please go throgh below link for more information http://codex.wordpress.org/Function_Reference/wp_nonce_field
How to save multiple metaboxes?
wordpress
If I have a custom post type called Drink which has permalinks like <code> /drink/pepsi/ </code> then <code> /drink/ </code> will list all of the Drinks. How can I rewrite <code> /drink/ </code> to <code> /drinks/ </code> ? I want permalinks for single Drinks <code> /drink/pepsi </code> to stay with the <code> /drink/ ...
When you register your custom post type , set the <code> has_archive </code> argument to the slug you want for the archive page, in this case <code> drinks </code> : <code> $args = array( 'rewrite' =&gt; array( 'slug' =&gt; 'drink' ), 'has_archive' =&gt; 'drinks', ); </code>
What is the simplest way to create a redirect
wordpress
Here is a simple example of what I am wanting to figure out. Say I have WordPress set to show 5 posts per page. And say I there is a post 17 posts back chronologically. The formula would be 17 / 5 = 3.4. Round up 3.4 to a whole page of 4 and that post 17 posts back is on the 4th index page. Now... How to do this progra...
Thanks to the stackexchange-url ("suggestion") of stackexchange-url ("Mridul Aggarwal"), I came up with the following query, which returns a post's chronological position for a given post id. The post id, post title, and post date can be removed and are just used for debugging / verifying the results. <code> SELECT * F...
How to find what index page a post is on?
wordpress
I'm using the _s theme and seeing the header menu point to 'Home' and 'Sample page'. in <code> functions.php </code> , we have <code> register_nav_menus( array( 'primary' =&gt; __( 'Primary Menu', 'mytheme' ), 'secondary' =&gt; __( 'Secondary Menu', 'mytheme' ), ) ); </code> Then in <code> header.php </code> , we use <...
You should be calling the menus by name, not description: <code> &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'primary' ) ); ?&gt; &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'secondary' ) ); ?&gt; </code>
Using _s theme, menu changes do not affect header menu
wordpress
What is the function reference for the text within the URL field in the Admin Menu page? I have a PHP function that is utilizing <code> the_content </code> function reference to look for specific file paths and replace said file path with a custom path. My goal is to apply this function that is successfully changing pa...
There doesn't seem to be a single filter just for a menu item URL, but in <code> wp-includes/nav-menu-template.php </code> there are a few filters: <code> wp_nav_menu_objects </code> - the menu items before being formatted with HTML <code> wp_nav_menu_items </code> - a HTML list of the navigation menu items <code> wp_n...
Function Reference for custom link in Admin Menu Management Page
wordpress
I am getting a custom field outside the loop in header.php. I get the custom field just fine but I found that when the custom field is empty, I get an error message <code> Trying to get property of non-object </code> Here is my code <code> &lt;?php $description = get_post_meta( $post-&gt;ID, 'page-description', true );...
Try this: <code> &lt;?php $description = get_post_meta( $post-&gt;ID, 'page-description', true ); ?&gt; &lt;div id="page-title"&gt; &lt;?php if( $description !='' ) { ?&gt; &lt;p&gt;&lt;?php echo $description; ?&gt;&lt;/p&gt; &lt;?php } ?&gt; </code>
get_post_meta property of non object
wordpress
Currently, there is a sidebar dedicated to all posts, and one for all pages. What I would like to do is target specific page templates to display sidebars for each template. <code> if(is_front_page()) { if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Blog Sidebar") ) : endif; } else if(get_post_type($post...
WordPress is very accommodating when it comes to conditionals: <code> if (is_page_template('products.php')) { ... </code>
Targeting specific Page Template for sidebar page
wordpress
how can I fetch a list of registered users and show it in the admin panel. I know theres the list inside the admin panel already but I've added a few tables and I need to show them in a new tab menu inside the admin panel.
What you've done is incredibly bad practice, and should be undone immediatley. There is already a dedicated table for storing user details aka User Meta. Altering the user table could cause issues with other plugins and Core, prevent upgrades working, and bypasses all the caching and object stores WordPress puts in pla...
get user list in admin area
wordpress
Does a theme's text domain have to be the actual theme name? If you develop WP themes, couldn't you just use the same name (perhaps your business name) for all the theme's you develop, making it easier to copy and paste code as you develop? (even though a find and replace is rather simple).
The text domain is a unique identifier, which makes sure WordPress can distinguish between all loaded translations so Using the basename of your plugin/theme is always a good choice because plugin/theme basename is always unique though it is not mandatory to have plugin/theme basename as text domain, you can use any un...
Does the textdomain have to be the theme's name?
wordpress
The codex lists both create_users and add_users under roles and capabilities . Does anyone know what is the difference between these two?
I explored WordPress to find difference between it and in schema.php file i found the following function only where in WordPress add_users capability is used. <code> /** * Create and modify WordPress roles for WordPress 3.0. * * @since 3.0.0 */ function populate_roles_300() { $role =&amp; get_role( 'administrator' ); i...
What is the difference between "create_users" and "add_users" capabilities?
wordpress
I have this code to the file category.php : <code> &lt;?php get_header(); ?&gt; &lt;div id="content"&gt; &lt;div id="all"&gt; &lt;div id="todo"&gt; &lt;?php $my_query = null; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $my_query = new WP_Query(array('post_type'=&gt;array('post','articulo'), 'paged' ...
The issue is that pagination is based on the main query . Whether or not pages exist is determined by the query that is run before the template is loaded. When you create a new query in the template, it's not connected in any way to that default main query. The proper way to alter the main query is via the <code> pre_g...
Custom post-type's pagination not working in category.php
wordpress
I want to do a task only once after an user has visited my site. I am currently doing like this: <code> function my_task(){ //do my tasks } add_action('init', 'my_task'); </code> I am doing this from a plugin. This actually loads my_task() function every time users load any page of wordpress. But I only want to load it...
There are various ways to do this, but I've recently addressed a similar problem by using cookies. <code> add_action( 'init', 'wpse_93797_cookie' ); function wpse_93797_cookie() { if ( !isset ( $_COOKIE['wpse_93797_cookie_name'] ) ) { // Do your stuff. // Set your cookie so we don't do stuff the next time around. // No...
How to do a task only once for logged in users
wordpress
I'm trying to get my head around a fairly simple concept in PHP but I'm pretty green. I have a function.. <code> function pa_insertPage($atts, $content = null) { // Default output if no pageid given $output = NULL; // extract atts and assign to array extract(shortcode_atts(array("page" =&gt; '2404' // Value for Course ...
This isn't really a WordPress question... that said <code> $recClasses = pa_insertPage($output); </code> is incorrect. here you should be passing to insertPage whatever the arguments are. Then insertPage will return $output, making $recClasses the same value as $output. <code> $recClasses = pa_insertPage('your attribut...
Using Output from one Function and calling it into another
wordpress
I need to tell whether or not the current custom taxonomy archive page I'm viewing has child categories. I've got a situation where there are a lot of custom categories with children and the site is only to show posts at the end of the line. Otherwise it should show a link to the category that's the next step down. I'v...
There may or may not be a better way to do this, but here's how I would do it: <code> $term = get_queried_object(); $children = get_terms( $term-&gt;taxonomy, array( 'parent' =&gt; $term-&gt;term_id, 'hide_empty' =&gt; false ) ); // print_r($children); // uncomment to examine for debugging if($children) { // get_terms ...
Check if Current Category has Children
wordpress
I encountered a strange problem with my JavaScript (jQuery) when trying to modify the behavior of my Media Uploader in Wordpress 3.5 This was my JQuery: <code> $('.attachment-filters').change(function(){ if($(this).val() === 'uploaded'){ alert("Uploaded images selected"); } else { alert("Other option selected"); } }); ...
The solution was to simply wrap my JQuery in a function like this: <code> $('#wpcontent').ajaxStop(function() { $('.attachment-filters').change(function(){ if($(this).val() === 'uploaded'){ alert("Uploaded images selected"); } else { alert("Other option selected"); } }); }); </code>
Wordpress Media Uploader custom Javascript not working
wordpress
I wanted a code in Wordpress that could allow me to republish the post every time I add a new custom field. For example, if I already have a post and wanted to add an update to it; I want it to appear at the top of the site after updating it. Is that possible ? Thanks in advance
It can be achieved by scheduling the post time to current time + a few seconds for example. Each time you add a custom field, just before saving - change the publish time to the current time and then save.
I want my post to republish again after adding a custom field
wordpress
I'm trying to localise a site (Canvas child theme). I already have the translated .po and .mo files. I uploaded the WooCommerce translation files to <code> child-theme/woocommerce/i18n/languages/ </code> in the child theme and the Canvas translation file to <code> child-theme/lang/ </code> . This follows the same direc...
There was a syntax error in loading the WooCommerce translations and I managed to get the parent theme translations working by following the same method I used for the WooCommerce translations. <code> function weg_localisation() { unload_textdomain( 'woothemes' ); load_textdomain('woothemes', get_stylesheet_directory()...
Loading Canvas & WooCommerce translation file in child theme
wordpress
I'm trying to show the last 5 posts from a specific category, which will be linked to a function so i can insert the shortcode in a Wordpress page. The code i have is as below, it does everything i need (although i want to add featured image too) except it does not show posts from a specific category. I've tried numero...
Here is the correct way to run this. I am using <code> 'category_name' </code> in theme code lately as it is much easier to read and remember. It uses the category slug. Here I am retrieving the last 5 posts in "uncategorized". <code> function Last5posts() { $args = array( 'posts_per_page' =&gt; 5, 'category_name' =&gt...
Show last 5 posts from specific category
wordpress
What is the cleanest way to display a text message beside the submit button like this in screen shot: I am currently doing it by editing the file <code> wp-includes/comment-template </code> line <code> 1577 </code> (wordpress 3.5) before: <code> &lt;input name="submit" type="submit" id="&lt;?php echo esc_attr( $args['i...
You should not edit the Wordpress core files! If you have <code> comment_id_fields() </code> in your comments template, like this: <code> &lt;p class="form-submit"&gt; &lt;input name="submit" type="submit" id="&lt;?php echo esc_attr( $args['id_submit'] ); ?&gt;" value="&lt;?php echo esc_attr( $args['label_submit'] ); ?...
adding a text message beside the comment submit button
wordpress
INdex.php, page.php and single.php all three files under the theme folder have the Loop to check for posts. Which one get execute first, and the next? What's sequence for Wordpress to read those files?
In general, the most specific template will be used first if it's available, then WordPress will try the others. It depends on what thing you're looking at (post, page, taxonomy, etc) and where your're looking at it (archive, single). This is all explained in detail by the Template Hierarchy .
Under Theme folder, what's sequence of action for index.php, page.php, single.php?
wordpress
We use a very customized version of WordPress for some of our index/root site pages where we use a custom meta box for custom permalinks. What we are looking for is a custom function that basically looks to see if the custom permalink field is being used and if it is, to grab that as the canonical url. This helps with ...
What you need is <code> get_post_meta </code> instead of <code> get_post_type </code> This: <code> if ( get_post_type( $post-&gt;ID ) == 'design' ) { </code> Should be: <code> $meta = get_post_meta($post-&gt;ID,'your-meta-key',true); if (!empty($meta)) { </code> Put altogether <code> function design_canonical_wpse_9371...
Custom Function for SEO by Yoast plugin
wordpress
I'm using <code> wp_list_categories(); </code> to show a list of all the terms within a custom taxonomy but I need to style list items that have children differently to those that don't. Is there a way, PHP or jQuery, that I can give all parent elements a special class?
jQuery solution: You could try this if you want to use jQuery: <code> &lt;script&gt; jQuery(document).ready(function($) { $('li.cat-item:has(ul.children)').addClass('i-have-kids'); }); &lt;/script&gt; </code> to add the class <code> i-have-kids </code> to all the <code> li </code> parents that include the items <code> ...
wp_list_categories, Add class to all list items with children
wordpress
I am using this code to filter posts. How can I modify to display only one category and its subcategories. Not all categories. <code> &lt;form action="&lt;?php bloginfo('url'); ?&gt;/" method="get"&gt; &lt;?php $select = wp_dropdown_categories('show_option_none=Select category&amp;show_count=1&amp;orderby=name&amp;echo...
Instead of: <code> $select = wp_dropdown_categories('show_option_none=Select category&amp;show_count=1&amp;orderby=name&amp;echo=0'); </code> put this: <code> $select = wp_dropdown_categories('show_option_none=Select category&amp;show_count=1&amp;orderby=name&amp;echo=0&amp;child_of=' . $ID_OF_PARENT_CATEGORY); </code>...
Display one category and its suncategories
wordpress
Here's the code I'm using to create yearly archives for a custom post type: <code> function myquery_custom_post_rewrite( $rewrite_rules ) { $myqueryslug = 'customposttype'; $month_archive = array( $myqueryslug . '/([0-9]{4})/?$' =&gt; 'index.php?year=' . $wp_rewrite-&gt;preg_index(1) . '&amp;post_type=' . $myqueryslug ...
Here's the code that worked: <code> function myquery_custom_post_rewrite( $rewrite_rules ) { $pagination_base = $GLOBALS['wp_rewrite']-&gt;pagination_base; $myqueryslug = 'customposttype'; $year_archive = array( $myqueryslug . '/([0-9]{4})/' . $pagination_base . '/?([0-9]{1,})/?$' =&gt; 'index.php?post_type=' . $myquer...
Paginate yearly archives for a custom post type
wordpress
I'm customizing a WordPress template and I would implement the following behavior in the excerpt posts visualization in my homepage: If a post contains images (one or more), in the homepage post preview show at the begining a thumbnail of the first image that is in the post, then show the excerpt of the post. At the mo...
if it is the "Featured Image" of your post, you can use: <code> &lt;?php // check if the post has a Post Thumbnail assigned to it. if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?&gt; </code> check: the_post_thumbnail function else if you want to get the first image inside your post, you can use somthing like th...
How to retrieve an image from a post and display it before excerpt of a post?
wordpress
If I enqueue my scripts selectively, for instance I have a slider I only want to load on homepage, which is activated in main-js, e.g: <code> wp_enqueue_script( 'main-js' ); if ( is_front_page() ) { wp_enqueue_script( 'slider' ); } </code> What is then the best way to do this? because all my jquery is in main-js and is...
If you're only enqueueing scripts when they're needed, you can check in JS if the plugin's namespace exists before trying to use it: <code> if( $.fn.slider ) { $('#slider').slider(); } </code> or another option is to pass some script vars via <code> wp_localize_script </code> : <code> $wpa_script_data = array( 'is_fron...
Enqueueing scripts selectively & activation where needed
wordpress
IN my Wordpress blog, I am looking to update a link in header that I believe is outdated: <code> &lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js?ver=3.5.1'&gt;&lt;/script&gt; </code> How do I get to this link? What file is it in? In my header.php file, I see <code> wp_...
If done right there should be a callback hooked to <code> wp_enqueue_scripts </code> which has either <code> wp_enqueue_script </code> or both <code> wp_register_script </code> and <code> wp_enqueue_script </code> in it. Something like the following from the Codex: <code> function themeslug_enqueue_script() { wp_enqueu...
How to Access Script Tags in Header
wordpress
Even that I got the code from the wp docs <code> &lt;a href="&lt;?php echo wp_logout_url( get_permalink() ); ?&gt;" title="Logout"&gt;Logout&lt;/a&gt; </code> This is the output when user clicks on it: <code> Warning: Cannot modify header information - headers already sent by (output started at /usr/home/nakashitabcn.c...
You shouldn't be echoing anything directly from your functions.php. Doing so will prevent redirects. Remove line 226 and you should be good to go. You might want to replace that whole remove_admin_bar with something better coded (or a plugin even).
wp_logout_url($redirect) won't logout and redirect ()
wordpress
I have a profile page, it is a template. Every time when I click one of a doctor, the profile page will show the specific doctor info by passing a query string. Something like profile?doctorName=abc. I have rewrote to profile/abc. Now the page title is "profile | blog name", But I would like to change the title to "abc...
use the wp_title filter. just remove all your code from header.php and put this into your plugin instead: <code> add_filter( 'wp_title', 'my_wp_title', 10, 2 ); function my_wp_title( $title, $sep = '|' ) { if ( is_page( physician_single_pg() ) and get_query_var( 'doctor' ) ) { $doctor = get_query_var( 'doctor' ); $titl...
How to customize a title by passing query string?
wordpress
I am looking for best option on Captcha. Plugin's don't seem to be the answer because this is a custom form for the theme I am using. Unfortunately, they don't offer any spam protection. The form is heavily styled so I do not want to start from scratch. I do have access to the contact form code and can plug one right i...
I'd say this question is mostly off-topic since it's not WordPress-specific. Mostly, because the majority of PHP solutions out there use sessions, which will not work out-of-the-box in WordPress. Google search actually handles this question quite well. Have a look at stackexchange-url ("this discussion") for nice techn...
Insert Captcha Code info Any Form (Created of Plugin)
wordpress
I have a custom wordpress query like so: <code> $query = new WP_Query(array('post_status' =&gt; 'future || publish', 'post_type' =&gt; 'kalender', 'order' =&gt; 'ASC')); </code> But the problem is that the items shown on the pages also include the items that are in the trash? I don't understand why because according to...
The syntax in the query above is wrong, it should be: <code> $query = new WP_Query(array('post_status' =&gt; array( 'publish', 'future' ), 'post_type' =&gt; 'kalender', 'order' =&gt; 'ASC')); </code> That seems to solve the problem. :)
Custom query shows custom post types in trash
wordpress
Is there a way that I can list all the terms within a custom taxonomy in an unordered list and wrap all child terms in another unordered list? For example; <code> &lt;ul class="menu"&gt; &lt;li&gt;&lt;a href="#"&gt;Parent 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt; &lt;a href="#"&gt;Parent 2&lt;/a&gt; &lt;ul class="sub-menu"&gt;...
You can take a look at the Wordpress function <code> wp_list_categories() </code> . If you want to display all the terms within a given custom taxonomy you can for example use: <code> &lt;?php $args = array( 'taxonomy' =&gt; 'my_custom_taxonomy_slug', 'orderby' =&gt; 'name', 'hide_empty' =&gt; 0, 'title_li' =&gt; '', '...
Show all terms in a custom taxonomy with all child terms wrapped in a ul
wordpress
The goal I want to use <code> wp_schedule_single_event( ) </code> to execute a single event that sends me an e-mail 8 minutes after the user submits a form. The issue The following code is in my <code> functions.php </code> : <code> function nkapi_send_to_system( $args ) { wp_mail( 'xxx', 'xxx', $args ); } add_action( ...
First can you please confirm that you don't have any caching plugins enabled? Caching plugins can interfere with cron jobs because your visitors are not served a live page but a cached version of your page. If you have a caching plugin enabled, you can choose one of your pages, add an exclussion to your caching plugin'...
WP Cron doesn't execute when time elapses
wordpress
Is there any way to prevent/hide trash button for comments? Note that I only want to prevent users from emptying the trash for comments. Can't seem to find a way. Is there any possible way to do that without plugin? But if I have to, I'll use a plugin. This is what I've tried so far, but not getting it to work. <code> ...
First, a note on you code: if you don't encapsulate the code of a conditional with curly brackets: <code> if($something){ encapsulated_actions(); } </code> it will only execute the next line. So, you should use: <code> if( 'post' != get_post_type() ) // if different of desired type, do nothing and return default return...
Function to prevent users from trashing comments
wordpress
I'm trying to pass two values to another page. Both pages are WordPress page templates. First, I pass the value as such: <code> &lt;tr onclick="window.location.href='http://www.areal-agro.nl/tool/?page_id=780&amp;amp;user=&lt;?php urlencode( the_title() ); ?&gt;&amp;amp;aanvraag=&lt;?php echo urlencode($current_aanvraa...
I'm assuming these are the post details the you're trying to pass through the URL. Not sure if that is the most effective way to go about doing this. I do the same type of thing, but pass the postID through the URL and when I get to the destination page, use the postID to collect the necessary information. If you're wo...
Passing multiple variables through url (php)
wordpress
We all know about the default WordPress post types, these being aside, gallery, status, chat and so on. any good theme should support all of them. In the case where a theme does support all of them, is it best, from a clean programming standard to do if, elseif, else if, else or should I use a switch case when checking...
You can use <code> get_post_format() </code> to build a conditional (or switch). <code> $format = get_post_format(); if ( 'status' == $format ) { // } else if ( 'quote' == $format ) { // } // etc. else { // get_post_format() returns FALSE for "standard" } </code>
Checking conditionals
wordpress
I'm displaying two posts on my main page, and using post pagination to go through the older posts. My problem is I want to change the layout a bit of the most recent post. This sounds like a very basic question, and I have seen a lot of answers, but they only solve the problem for the first post on the page, not the ac...
$pcount is counting how many posts you've gone through in the current loop, it isn't counting the number of pages. Think for a moment about what the loop is doing, if you're on page 2, why would you have the posts from page 1? It makes no sense, which is a sign that thinks aren't going to work. If what you have was eve...
Adjust layout most recent post, taking pagination into account
wordpress
Upon theme activation I want to create an 'URL' key for the custom fields. Like in . I know who to run functions when a theme is activated, I don't know how to create this custom field key though. Any thoughts? I don't want to be using custom meta boxes.
Those values are populated from the unique keys in the <code> *_postmeta </code> table, excluding keys that begin with an underscore ( <code> _ </code> ). If you want to pre-populate that key the add a value to the table under post ID <code> 0 </code> . There is no way to pre-populate those that I am aware of besides t...
Create custom field key upon theme activation
wordpress
I want to show the posts under a category in my page.The first 5 posts should be shown when the page loads and When the user clicks the next button/link next 5 posts should be shown. Currently I show all posts under the category.The following is the template I use to show all the posts under that category.I know I need...
You can use carousel javascript to get the desired output. There are various carousel available, you can use some thing like jcarousel . Download the js and css from the jcarousel website and en-queue it in your theme to use it. Note : You will have to manage the dependencies of it with jQuery. Let me know if you need ...
Jquery Slider for profile template
wordpress
I've been searching for a while for an answer to this, but the results I find always deal with custom post types as opposed to the built-in 'post' post type. I want to remove the default 'Post Tags' taxonomy from the built-in 'post' post type and then add my own custom taxonomy to replace it. Essentially, I have other ...
to completely remove post tags: stackexchange-url ("stackexchange-url if you want to remove post tags from posts, but keep on other custom post types: <code> add_action( 'init', 'my_register_post_tags' ); function my_register_post_tags() { register_taxonomy( 'post_tag', array( 'my_post_type_here' ) ); } </code> to add ...
Remove post_tag from default post type, add custom taxonomy
wordpress
Is there anyway to get the password string from the login form?
this should do the job, just add it to <code> functions.php </code> or put in a plugin: <code> add_filter( 'wp_authenticate_user', 'my_authenticate_user', 10, 2 ); function my_authenticate_user( $user, $password ) { // do whatever you want with the $password variable here return $user; } </code>
Is there anyway to get the inputted password string from the login form?
wordpress
I have some strange error or may be I do not have the skills to tackle this issue. I am building a plugin for Multisite. When is use <code> is_admin() </code> , my plugin works fine but when I use <code> is_super_admin </code> it shows me this error <code> Fatal error: Call to undefined function wp_get_current_user() <...
<code> wp_get_current_user() </code> is a pluggable function and not available when your plugin is included. You have to wait for <code> plugins_loaded </code> : <code> add_action( 'plugins_loaded', 'wpse_92517_init' ); function wpse_92517_init() { if(!is_super_admin()) add_action('widgets_init','my_unregister_widget')...
Fatal error: Call to undefined function wp_get_current_user()
wordpress
I am using Gravity Forms to let users create posts. The user fills out a bunch of information, and a post is created. The user gets to choose which categories the post is in, but there is one more category that I need to add for every post. I am trying to use the gform_after_submission hook ( http://www.gravityhelp.com...
Looking at core, it seems post_category always overwrites: <code> // Passed post category list overwrites existing category list if not empty. </code> Instead, try something like: <code> //wp_set_post_terms( $post_id, $terms, $taxonomy, $append ) wp_set_post_terms( $entry["post_id"], 48, $taxonomy, true ) </code> Obvio...
Gravity forms and wp_update_post
wordpress
I was looking for a tutorial on adding options to the "Edit Gallery" page. In the hopes of adding some GUI inputs that would result in the generated [gallery] short-code having custom attributes. I found stackexchange-url ("this question"). I was hoping that taking a look at how the page and options are rendered, and w...
Browsing through the code at http://core.trac.wordpress.org/ , it appears that the file you're looking for is <code> /wp-includes/media.php </code> . I wouldn't recommend editing core files, though; any updates you make would be clobbered in the next upgrade.
Which file renders the "Edit Gallery" Settings page?
wordpress
I've modified my website quite a bit and now looks almost as I desire. I've set all the posts to be commentable in Settings/Discussions but it seems that this imput is not saved and new posts by authors are not commentable. Everytime, I need to "quick edit" the new post and mark the |_|Allow Comments field as selected ...
A common method to keep all the posts open for comments, is to add this line into the file <code> functions.php </code> in the current theme directory : <code> add_filter('comments_open', '__return_true'); </code> where <code> __return_true </code> is just a core function that always returns <code> true </code> . ps: s...
How to make all the posts commentable by default? Imputs in Settings/Discussions are not saved
wordpress
I'm using Justin Tadlock's Members plugin to create new roles and WP Role on Registration to display them on the registration form. I've got a multilang site (English and Spanish) and I've localized my custom taxonomies using qTranslate. I can't use qTranslate's quicktags in the Role Label field on the Member's plugin ...
I don't know the function you mention either, but I would venture to guess that that applies to default roles only anyhow. Still, the link you posted does contain a pointer in the right direction. It speaks of "dummy gettext calls", which is exactly what you have to do. In the following we will adjust the global <code>...
Is there a way to localize role labels?
wordpress
I am using WP for my RealEstate project where all properties are pulled from a custom table (wp_listing) and displayed in a custom page template (page-realestate.php). I know WordPress has built-in pagination methods to deal with paged content (pages, posts lists). I want to use that same pagination methods for the lis...
It is unclear exactly which "built-in pagination methods" you are looking for. WordPress uses several. If you are looking for the <code> next_posts_links </code> and <code> previous_posts_link </code> functionality, write your own function as those built-in functions depend upon the <code> $wp_query </code> global as y...
Wordpress pagination on custom script
wordpress
I want to allow users to create username with + symbol. but wordpess removing the symbol by the register validation process. If I gave username as abcd+123 , the user registered with username as abcd123 . I need the username registered as it is with + symbol. Answers are greatly appreciated.
We need to add a filter to 'sanitize_user'. Here is the sample code that will work for you. add_filter( 'sanitize_user', 'tubs_sanitize_user', 10, 3); function tubs_sanitize_user($username, $raw_username, $strict) { $new_username = strip_tags($raw_username); // Kill octets $new_username = preg_replace('|%([a-fA-F0-9][a...
How to allow wordpress to create username with symbols like +
wordpress
Here's a brief summary of how my site is setup: I have a relatively simple Intranet site. Right now I am utilizing posts as a means to provide news to users. I am also using pages. I only want certain users to be able to do these things (let's say "Editors"). What I would like to do is to setup a community section of t...
The following will assign capability requirements to your CPT. So, users will require edit_community, delete_community etc capabilities to perform those actions. <code> function createCommunityPostType() { $args = array( 'public' =&gt; true, 'label' =&gt; 'Community' 'capability_type' =&gt; 'community', 'map_meta_cap' ...
How do I allow certain users to make a certain type of post?
wordpress
I'm writing a template to display my custom posts types in a list. But I only want to have the post show if it has a value for one of my custom fields. I'll explain: My custom post type is "Faculty Members" and the Custom Field is "awards" The page will display all Faculty members who have received awards and what ther...
If I understand you, you want to filter out faculty members who do not have any awards at the query stage. Replace your code: <code> &lt;?php query_posts( 'post_type=mtt_page'); ?&gt; &lt;?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?&gt; </code> with this (untested): <code> &lt;?php $args = array( 'po...
Display Posts Query with IF function
wordpress
I can't seem to upgrade my custom theme. Whenever I try to uploaded a new package, all I get is: Unpacking the package… Installing the theme… Destination folder already exists. /wp-content/themes/THEMENAME/ Theme install failed. I've searched and all I can find is people recommending upgrading over FTP. Sadly, I don't ...
It fails because there is already a theme with that name on the server. So the obvious solution is to remove the theme before you upload the new version. If you're wanting to use an update mechanism like the theme repo, but on a custom theme, there are udpater classes you can add, such as this one: https://github.com/U...
Upgrading a custom theme through the Dashboard
wordpress
How do I place the following javaScript in the <code> &lt;head&gt; </code> section of the Wordpress Widgets API menu screen? <code> &lt;script type="text/javascript"&gt; jQuery(window).load(function() { jQuery("#logocheckbox").change(function() { jQuery("#logocheckboxdiv").fadeToggle("slow"); }); }); &lt;/script&gt; </...
<code> function load_custom_logo_js($hook) { if( 'widgets.php' != $hook ) return; echo (' &lt;script type="text/javascript"&gt; jQuery(window).load(function() { jQuery("#logocheckbox").change(function() { jQuery("#logocheckboxdiv").fadeToggle("slow"); }); }); &lt;/script&gt; '); } add_action( 'admin_enqueue_scripts', '...
javaScript in section of WP API
wordpress
I would like to know, what is the best practice for updating the <code> header.php </code> file: From within WordPress editor: Appearance > Editor or Directly in the <code> header.php </code> file itself (in the www_root)?
This question leans towards getting some subjective answers, as I think it's a matter of personal preference. The built-in editor works just as well as any other text editor. That goes for any of your theme files, not just <code> header.php </code> . The benefit of using an external editor (like Notepad++ and using Fil...
Best practice to update the file header.php
wordpress
I'm almost done to create my project with WP and all the steps taken have brought me almost to the finish line. The following recent answers I had were able to help me customizing the comments area: stackexchange-url ("Comments screen in backend, how to disable Quick Edit | Edit | History | Spam | for non admins") stac...
If understood correctly, you are referring to the Quick Edit <code> Reply </code> action. There is no hook (a direct one at least) to hide that. It has to be CSS or jQuery. Like: <code> add_action( 'admin_head-edit-comments.php', 'hide_quick_reply_wpse_92435' ); function hide_quick_reply_wpse_92435() { echo "&lt;style&...
Comments screen in backend, how to disable visual editor when replying to a comment
wordpress
I'm considering rebuilding a drupal site in wordpress and am still wrapping my head around the differences between the systems - particularly cck/fields and custom content types and the different ways to use taxonomy. I would like to know if two custom content types can share one custom taxonomy. In drupal I can limit ...
Sharing a taxonomy between CPTs I would like to know if two custom content types can share one custom taxonomy. Simple said: Yes, they can . How to share As I elaborate in detail in this blog post, you should always register custom taxonomies and post types to each other as early as possible. Wrap your registration pro...
Can multiple custom post types share a custom taxonomy?
wordpress
I am using woocommerce plugin, and added some product categories in appearance-> menu. I mentioned that if I logging off, the product categories is not showing at all... please help. sorry for bad english.
I found the answer. The main problem is: First of all woocommerce plugin has own ID system. And wordpress has own ID system. And it happened that with the same ID was two different items. For example: Woocommerce category name "my category" has ID: 13 And Wordpress page "Logout" has ID: 13 So, in woocommerce where is f...
woocommerce product categories in menu
wordpress
I have a couple of long forms which I want to output as shortcodes. Shortcode API indicates that If the shortcode produces a lot of HTML then ob_start can be used to capture output and convert it to a string This seems to be exactly my case. Also, I want to use WordPress functions inside my HTML, like this: <code> func...
Should I just bring these forms out into templates instead? It depends on the form, and you haven't printed much detail about what your forms do. Shortcodes are nice but are not the right tool for every job. I would: Prefer a dedicated template to a shortcode, especially for long forms. You start to get into having to ...
Shortcodes, output buffering, and WordPress functions
wordpress
I'm trying to create a list on the frontend of my site of all media items that the current user has uploaded. It seems like the way to do this would be to loop through and compare the ID of the current author with the ID of the author of the media item and then only display the items when a match is found. But, I can't...
Media are just posts - so just query posts. This is untested: <code> $args = array( 'author' =&gt; $author_id, 'post_type' =&gt; 'attachment', ); $query = new WP_Query( $args ); </code> I'm not sure if you want currently logged in user or the author of the post currently in the loop - either way you can set $author_id ...
Get all media files for current author
wordpress
I would like to be able to hide W3 Total Cache from non admins. How can I go about doing so? The following code I tried implementing in my functions.php file does not work: <code> function hide_w3tc() { if (!current_user_can('super_admin')) { remove_submenu_page('admin.php?page=w3tc_dashboard'); } } add_action( 'admin_...
You can try to use <code> remove_menu_page() </code> , so you code example would be like: <code> function hide_w3tc() { if (!current_user_can('manage_network')) { remove_menu_page('w3tc_dashboard'); } } add_action( 'admin_menu', 'hide_w3tc',11); </code> where we use a priority greater than the default of <code> 10 </co...
How to hide W3 Total Cache from non admins?
wordpress
I'm trying to configure the comments screen in the backend to fit my project. I've already been able to take a first step by resolving this question: stackexchange-url ("Comments screen in backend, how to disable Quick Edit | Edit | History | Spam | for non admins") Now I'd like the post author viewing all the comments...
There is a filter <code> 'comment_email' </code> . Hook into that filter after the action <code> 'load-edit-comments.php' </code> and hide the email: <code> add_action( 'load-edit-comments.php', 't5_hide_commenter_email' ); function t5_hide_commenter_email() { if ( ! current_user_can( 'manage_options' ) ) add_filter( '...
Comments screen in backend, how to disable email address of commenter for non admins
wordpress
What Im looking to do is look if on one page out put posts that have 2 cats selected (they must have both selected to be shown, not just one cat) <code> if (is_page(15) || $post-&gt;post_parent=="15") { $option1 = '11, 4'; $option2 = '11, 7';} &lt;?php $my_query_args = array( 'posts_per_page' =&gt; 10, 'meta_key' =&gt;...
Your query has some odd elements like <code> 'meta_value_num' =&gt; '', </code> but it sounds to me like what you want is exactly what <code> category__and </code> does . <code> $my_query_args = array( 'posts_per_page' =&gt; 10, 'meta_key' =&gt; 'price', 'category__and' =&gt; array($catid1,$catid2), 'orderby' =&gt; 'me...
output only if within a combination of two cats
wordpress
I have a WordPress 3.5.1 installation on my WordPress Shack , with the Facebook plugin 1.3.1 installed and the TwentyTwelve 1.1 theme. I have the settings on Facebook - Comments box so that I display the comments box on posts and pages. In Settings - Reading, I checked a static page as front page, "Welcome". I've check...
Fast 'n' Hacky The problem can be solved by changing line 319 in <code> facebook.php </code> to the following: <code> if (is_home()) { </code> This way, the front page is not treated as a home page but as a regular page, for which the facebook feature settings can be applied (and will be handled correctly). More Elegan...
Facebook comments box on front page
wordpress
I want to "save" my menus into transients. I want to update those when there's been any changes to the menus via the admin custom menus. I've looked for an action but can't see to find anything. Perhaps I missed the obvious?
http://adambrown.info/p/wp_hooks/hook/wp_update_nav_menu?version=3.5&amp;file=wp-includes/nav-menu.php : <code> do_action( 'wp_update_nav_menu', $menu_id, $menu_data ); </code> Consequently, a nav menu is a custom post type, as are its menu items, so all of the usual hooks for publish/save/update/trash apply
Is there an action for save_menu and/or update_menu?
wordpress
Recently I've done a nice taxonomy system on my WordPress website. Created also the taxonomy archive template files, so wherever I'm listing the taxonomies I can click on them and will bring me on a results page filtered by the clicked taxonomy. I'm wondering if the same situation can be reproduced also with custom fie...
WordPress does not support by default <code> custom_field </code> s archive like for taxonomies ( yeah, taxonomies can have categories ) but we can create a destination page with page template ( linked from the listed <code> custom_field </code> ) and added a searching on the <code> custom_field </code> , like this ( f...
Archive for custom fields?
wordpress
I have 5 main posts within a custom post type. Some of these posts will have children. I have content that should only be displayed on the parent post and all children of that post. What's the best way to achieve this?
You could setup a condition based on post ID: <code> &lt;?php if (is_page(12) || $post-&gt;post_parent=="12") { ?&gt; &lt;ul&gt; Your Menu &lt;/ul&gt; &lt;?php } else { ?&gt; &lt;ul&gt; Another Menu (or put nothing here) &lt;/ul&gt; &lt;?php } ?&gt; </code> If you don't know how to locate the post ID: "Roll over any pa...
Show specific content on parent custom post type and all children
wordpress
I built a few static pages in HTML while I was practicing some techniques. I would like to include those pages (and that hard work) in a word press site. I have already created the WP page that hold the 6 items that I want to use as links to my work. I would like to link to another spot on my server or site that will t...
I would suggest making your own page template . Start by moving the files into your WordPress theme folder, and giving them a name. Like <code> page-foo.php </code> , <code> page-bar.php </code> , so on. Then on the top of these new files add PHP like the below, changing the <code> Template Name </code> to something th...
Using static pages on Wordpress site
wordpress
I am literally clueless as to why the code does not function properly on the first page, but functions as expected on the second page. I have already tried running the second query via another WP_Query() to no avail. See for yourself: http://blog.donovanglover.com/ The second query should return the latest 3 posts in t...
I see a number of issues, aside from the use of query_posts ( this should raise immediate alarm bells ). I strongly recommend you don't use the alt syntax, and that you minimise the unnecessary opening and closing PHP tags as it obscures your code. Here is a cleaned up version of your first query loop: <code> if(have_p...
Why is the first query affecting the second query, even after wp_reset_query() and wp_reset_postdata(), but not on the second page?
wordpress
The function below controls an option inside an options panel. What it does is choose the number of posts being displayed in a particular archive (to_count archives, to_count_home, to_count search are assigned to the homepage, archives.php, and search results respectively). When I change the number of posts being displ...
You can try to add the condition <code> $query-&gt;is_main_query() </code> in your <code> if </code> -sentences so it won't affect the gallery queries: <code> // Posts per page add_filter('parse_query', 'wpq_parse_query'); function wpq_parse_query($query) { if(!$query-&gt;is_main_query()) { return $query; } if($query-&...
Functions Error: Impacting Galleries
wordpress
I am using the $wpdb class to do a custom SQL query but I am getting weird results. Basically this is what my SQL query is supposed to do Retrieve the titles of post_types 'question' only if they are published within the last 7 days have a taxonomy of 'question_tag' have the terms 'another-sample' or 'sample' The probl...
This may be your problem: <code> $wpdb-&gt;terms.slug = 'another-sample' OR $wpdb-&gt;terms.slug = 'sample' AND //the date logic doesn't seem to qork quite right $wpdb-&gt;posts.post_date &gt; DATE_SUB( NOW(), INTERVAL 7 DAY)"; </code> Your OR operator might be confusing the query. Try using parentheses: <code> ($wpdb-...
Custom $wpdb returns unexpected time based results
wordpress
My theme currently uses add_menu_page() in order to display the theme options sections on the left hand admin menu. I would like to be able to attach a parent css class to the main menu item in order to selectively show/hide the menus for advanced users. I don't see this documented in the codex so I'm asking here to fi...
You should not do this via CSS as the underlying functionality would still be there (and thus open for direct access). I'd rather rewrite the theme in a way that the menu pages are only added if the current user has a certain capability. <code> if (current_user_can( SOME_CAP )) { add menu pages ... } </code> You could ...
Pass custom css class to add_menu_page
wordpress
I'm using code below to spit out custom post types along with its categories, so Category 1 ---post 1 ---post 2 Category 2 ---post 1 ---post 2 ---post 3 etc. That works well for me, however I would like to be able to sort my categories by count so orderby=count so catgories with larger amount of post will go to the top...
You have <code> orderby=count </code> , which should be correct , but you also have <code> order=asc </code> . <code> order=ASC </code> means "smallest to largest", at least with numbers. You want the opposite, "largest to smallest". Use <code> order=DESC </code> instead. I suspect that <code> get_terms </code> is work...
Categories sorting
wordpress
I'm using the code below to track when a user last logs in. I'm realizing though that if they checked the <code> Remember Me </code> option, this won't track their last visit . <code> // Catch the time they login and save it function set_last_login($login) { $user = get_userdatabylogin($login); update_usermeta( $user-&...
You could create a new entry for the user meta data and update it on every admin pageload. Put the following in your theme's <code> functions.php </code> or maybe wrap it into a plugin: <code> function update_last_action_time() { $user = wp_get_current_user(); update_user_meta($user-&gt;ID, 'last_action_time', current_...
Tracking last login and last visit
wordpress
I am using the below mentioned code to get top 5 child categories (by number of posts) from a Parent category. The code works fine , however I need to add more "Parent" categories so that I cant get total of Top 5 child categories from multiple parent categories. <code> Adding 'parent' =&gt; '599,588,590', **Does not w...
You cannot get it in one call. Instead, make multiple calls, then sort the data each call gave you into a single array, and take the top 5 in the new list. e.g. <code> $args=array( 'orderby' =&gt; 'count', 'order' =&gt; 'DESC', 'parent' =&gt; '599', 'number' =&gt; '5' ); $categories=get_categories($args); $args2=array(...
Adding Multiple "Parents" in get_categories
wordpress
I am having some issues with a couple of plugins which use jQuery/JS i.e. cookie control and a picasa photo gallery. The theme I am using is quite basic and comes with no sliders etc with moving parts and therefore maybe HAD no need for for jQuery/JS so may not be included in the theme. I have tested the exact same set...
Not entirely sure what you're asking but you have to include and register scripts and then enqueue what you require like:- <code> &lt;?php wp_enqueue_script('jquery'); ?&gt; </code> (Place immediately before <code> &lt;?php wp_head(); ?&gt; </code> ). Which is included with Wordpress incidentally. You can read more on ...
WordPress Theme - jQuery JavaScript Library Issue
wordpress