question stringlengths 0 34.8k | answer stringlengths 0 28.3k | title stringlengths 7 150 | forum_tag stringclasses 12
values |
|---|---|---|---|
How do I make it a variable product and add variations? Are variations handled like attributes? this code creates a product and adds an attribute(XL size) but i cannot make that attribute used as a variation, width a custom price(etc). this is a function called via ajax <code> function createnewproduct(){ $new_post = a... | Found the solution to make a product attribute, a variation. Lets say we have <code> wp_set_object_terms( $post_id, 'XL', 'pa_size' ); </code> The above is a custom attribute (a size attribute). Making it a variation will look like <code> $thedata = Array('pa_size'=>Array( 'name'=>'pa_size', 'value'=>'', 'is_v... | Adding a Variable Product in WooCommerce Programatically | wordpress |
I have a function that whenever i add a new post in the custom post type "artists" it adds a new term with the same name in the custom taxonomy "artists". <code> function add_artist_category_automatically($post_ID) { global $wpdb; if(!has_term('','byartist',$post_ID)){ $cat = get_the_title($post_ID); wp_set_object_term... | do you know where is your code fails? Is the hook runs properly? One thing for sure, term_exists() returns the ID not an object. Also $wpdb is not needed at all. <code> wp_delete_term($theterm, 'byartist'); </code> | Function to delete a term when a custom post with the same slug is trashed | wordpress |
Is it possible to give a custom post type its own category box? If I use <code> 'taxonomies' => array("category") </code> or <code> register_taxonomy_for_object_type('category', post_type); </code> I get the desired box but it shows all categories across all post types. I want the displayed values in the meta box to... | Create a custom taxonomy (as you have) except change the <code> hierarchical </code> argument to <code> true </code> for the meta box to behave like the default categories taxonomy: <code> 'hierarchical' => true </code> | Custom post type specific category box | wordpress |
I am curious whether Wordpress is able to run nested <code> meta_query </code> , with each having different relation keys? As of Wordpress 3.0, <code> tax_query </code> is able to perform this function; I'm wondering whether this has an equivalent with <code> meta_query </code> . <code> $results = query_posts( array( '... | That seems to be impossible. Please someone correct me if I'm wrong. The <code> meta_query </code> parameter will actually be transformed into a <code> WP_Meta_Query </code> object, and the <code> relation </code> verification won't go deeper in <code> wp-includes/meta.php </code> , and occurs just once in the top leve... | Nested meta_query with multiple relation keys | wordpress |
I'm trying to show aditional posts in the author's page. This page must have posts containing a specific <code> meta_key </code> and <code> meta_value </code> , where the displayed author it is not really the WP post's author. This is the function I have: <code> function my_pre_get_posts( $query ) { if ( is_admin() ) r... | The WP_Query class will automatically <code> AND </code> any filters that are set. In your case, using <code> $query->set( 'meta_query', ... ) </code> means that WordPress will be looking for posts from the current author (because this is the author template) AND that have your custom meta key. From my understanding... | Show posts containing or not custom field | wordpress |
I have a magazine like post structure like so: <code> Parent -> Sub category -> Article </code> . The parent is the issue, the sub categories are the sections within the magazine like news and interviews etc and then the articles are within those sections. I have background images which are associated with the su... | Your code is failing because the first term is the parent term, caused by checking both the parent and the child term. You dont need to do that, if I have a heirarchy A-> B-> C-> post, and I add the post to the C category, it's automatically a part of its parents | Posts not listing out sub category in hierarchy | wordpress |
I am developing a WordPress theme, and when reading the Codex article on Theme review, WP recommendeds against allowing custom favicons in a theme. Does anyone know the reason for this recommendation? From the Codex: Favicons Themes are recommended not to implement custom favicon functionality. If implemented, favicon ... | Probably because a thing like a favicon is not necessarily tied to the on-page design, but to the branding of a site in general. In other words: it's not specifically part of the "display" of the site. If a theme does choose to implemented it, an ender user might not want it (opt-in only) or they may want to use their ... | Why does WP recommend against custom favicon functionality in themes? | wordpress |
I use this code to get tags from category. stackexchange-url ("get all tags from category") I want to display in the category page the specific tags. I have 8 categories and this is my code: <code> <?php if (is_category('10')) { ?> <?php $args = array( 'categories' => '10' ); $tags = get_category_tags($args... | If you use <code> get_terms() </code> , then you can retrieve all terms for a given taxonomy (this includes category as well as post-tag). To get the category on a category archive page, you can use <code> get_category( get_query_var( 'cat' ) ) </code> which will give you an <code> object </code> of the currently displ... | Get tags specific category | wordpress |
I've some specific use case for certain default wordrpess tables, which I need to add a few indexes to certain columns to improve performance. I'm wondering will adding these indexes break future Wordpress update when they choose to add index to the same column? | Adding a <code> BTREE </code> or <code> HASH </code> index shouldn't break anything, and I imagine that is what you want. At worst you could end up stackexchange-url ("with multiple indexes, or less than optimal ones, which might negatively effect performance"). I assume that if you are going to do this you will be eva... | Will adding & modifying default Wordpress table index break future Wordpress update | wordpress |
I'm creating a batch uploader and it would be good if I could also add categories with parent categories to my posts. I have the following code: <code> $my_cat = array( 'cat_name' => $cat_name, 'category_description' => $cat_desc, 'category_nicename' => $cat_slug, 'category_parent' => $cat_parent); if(funct... | <code> wp_insert_category </code> and <code> wp_create_category </code> are both in wp-admin/includes/taxonomy.php. They're not general use functions and can't be used just anywhere . <code> wp_insert_term </code> is, but you're using it incorrectly. See the Codex for details on proper usage, but in short, here's a che... | creating categories programmatically | wordpress |
I am building a web app and would like to use the Wordpress Engine only for Authentication and User Management. Is there any good tutorials out there on how I can connect only the back end of wordpress to my simple app? | This may be good starting point for you: http://codex.wordpress.org/Integrating_WordPress_with_Your_Website http://codex.wordpress.org/Developer_Documentation (see function reference for admin-related functions list) | Use Wordpress engine for user registration and management | wordpress |
I'm trying to add a java script file to my admin header and use admin-ajax.php to use ajax in my wp-admin (still learning a lot about the process). I've created a custom folder in my theme_directory/js called custom with the file I need to add to the admin header but it doesn't seem to be working. here's the code: <cod... | Ahh ok I figured it out while researching. I needed to add the $hook parameter and pass it to my function like so: <code> function my_admin_enqueue_scripts($hook) { global $current_screen; if ( 'post.php' != $hook ) return; wp_register_script('my-scripts', get_template_directory_uri() . '/js/custom/my-scripts.js' ); wp... | Trying to get custom js files in my admin header | wordpress |
I have a custom post type to get images. I am setting up my theme to display a specific way when it is first installed. For some reason, my code is stopping the bottom half of my page from displaying. <code> <div id="gallery"> <?php if( $loop->has_posts()): ?> <hr /> <h1 class="tag-background"&g... | I think your issue is <code> $loop->has_posts() </code> . Try <code> $loop->have_posts() </code> . | why is my custom loop failing? | wordpress |
I want to set a custom title to indiviual rss feeds. Right now my post feed runs under a page called podcasts and the title of my rss feed then becomes <code> <blog name> » podcasts </code> because it is the feed of the podcasts page. However I would like to replace the slug <code> » podcasts </code> with the sub... | Easy Fix ... since I use feedburner I can use their "burn feed title" service, which does exactly what I want! | Change rss title of individual feeds? | wordpress |
I have a custom role that allows access to only a sigle custom post type. This is all well and good, but now it is only showing up for this role, not for admin and super admin. I'm having a hard time getting it to show up in the admin dashboard. <code> add_role( 'artists_relations', 'Artist Relations', array( 'post_art... | First off, @Wyck is right, it would be helpful to see your <code> register_post_type </code> code. If it were me, I'd make sure I had something like this in the <code> $args </code> array: <code> register_post_type( ... array( 'capability_type' => 'artists', 'map_meta_cap' => true ) ); </code> Next, you don't wan... | Apply custom role capabilities to administrator (without plugin) | wordpress |
I'm struggling with the query for this in WordPress to display posts in a category from the 6th most recent onwards. Basically, I have a top 5 posts section at the top of a category for featured posts (marked as posts in that specific category AND in a Featured category), then in the page content I don't want any of th... | Without seeing your code, here's a rundown that should work for you. At the top of your template file, start an array, <code> $featured_posts = array(); </code> In your featured posts loop, in each iteration, add the ID of the post to the array, <code> $featured_posts[] = get_the_ID(); </code> In your second loop, chec... | Show posts in category x and y from the 6th most recent post onwards | wordpress |
I use the code to get all the meta boxes values in a custom type <code> <?php $args = array('post_type' => 'posttype'); $emptyvalue = ""; $optionname = "optionname"; $the_query = new WP_Query($args); $output ="<select name='".$optionname."'> <option value='".$emptyvalue."'>Location</option>'"; w... | Solution I created array outside the while loop and checked if the value is in array or not. <code> <?php $args = array('post_type' => 'posttype'); $emptyvalue = ""; $optionname = "optionname"; $the_query = new WP_Query($args); $output ="<select name='".$optionname."'> <option value='".$emptyvalue."'>... | Remove duplicated values from meta box values | wordpress |
I have displayed the custom taxonomies in the drop down as you see in the red box i want to ask that how can i submit them with the post .I can't figure it out.` <code> // Do some minor form validation to make sure there is content if (isset ($_POST['title'])) { $title = $_POST['title']; } else { echo 'Please enter the... | Update your form to include the term-id, instead of just <code> <input type="checkbox" /> </code> use <code> <input type="checkbox" name="taxonomy_id[]" value="'. $industryterm->term_id .'" /> </code> . That way you are actually sending along some values, in this case the term id. And in the args for <co... | Form to post new post with custom taxonomies | wordpress |
I added the lines <code> define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' ); </code> and <code> define( 'WP_CONTENT_URL', 'example/blog/wp-content';); </code> in my wp-config.php and then my site broke. Even some of the widgets on the backend do not appear anymore. I immediately removed the abov... | There're some things you should not play around with, until you really know core inside out and one of those things are the Path constants that can be set in your <code> wp-config.php </code> . Here's how I do it. Note, that it's uncommented, so it doesn't trigger and WP uses its default. <code> # define( 'WP_CONTENT_D... | Changing the wp-config.php broke the site | wordpress |
I'm working on a theme that has a number of image sizes defined correctly using: <code> add_image_size( 'name', 500, 200, true ); </code> I would like to override these defined sizes from the child theme: <code> add_image_size( 'new-name', 400, 300, true ); </code> I know I can add new sizes, but if I add the same name... | The <code> add_image_size( $name, $width, $height, $crop ) </code> function is graceful enough to handle multiple calls using the same <code> $name </code> . It simply overwrites the existing value : <code> $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'cr... | remove or update add_image_size | wordpress |
I am working on a wp site where I need to manage 500s of child pages for a single page such as About menu can have more child pages need to manage those child pages as sub menu and I have more than 5 such menus. My client is saying that it will cause load to the server. Does this create a problem in server? If yes, is ... | In general it should not be a big problem. The built of the menu could be slow, so your best option here is to cache the menus with transient. <code> if ( !get_transient( 'first_menu_transient' ) ) { ob_start(); // do not directly output the menu // build the menu $first_menu = ob_get_contents(); ob_end_clean(); echo $... | Does loading of sub pages in menu cause load to the server? | wordpress |
I am having a strange issue with permalinks while using the <code> /%postname%/ </code> structure. I can access my custom post types using the pretty permalink <code> localhost/cpu/<post-type>/<post-title>/ </code> but I am getting a 404 error on Pages. The url of a page is <code> localhost/cpu/<page-tit... | can you try replace <code> RewriteRule . /cpu/index.php [L] </code> by <code> RewriteRule . /index.php [L] </code> as for a way to debug... well you can always var_dump a $wp_query object to get an idea what variables not passed to wp. (you can place ) into first line of your header.php template. and i belive next step... | 404 permalink errors on Pages only | wordpress |
I want to upload text and a video for a future date. On that future date, a new post/html is added to the site (without me doing anything that day). | Unless I'm misunderstanding you, you should just need to set the publication date of the post in the future and "Publish" it. This should walk you through you what you need to know: http://wordpress.tv/2009/01/14/publishing-your-post-at-a-later-date/ | pre-upload text and video for the future | wordpress |
I want to disable author pages for certain users, for example the admin user doesn't post anything but still has an author page. Is that possible? Maybe a plugin that adds an option to the users page in the admin panel to enable/disable the author page? | I think a combination of the answers so far along with an admin area field to disable the author archive(s) is the best bet. A class to wrap everything up (along with some constants and methods that will be clear later): <code> <?php class Author_Archive_Disabler { // meta key that will store the disabled status con... | Disable author pages for specific users | wordpress |
What is the wordpress wp-includes folder for? That is, whats the fundamental architectural purpose of it, for example why isn't it all in themes or an admin folder? Can a plugin developer rely in it's contents (e.g. jQuery) and for how long? I would also like to know, who decides what goes in there and how does it get ... | <code> wp-includes </code> contains everything needed to run WordPress via the frontend ( and then some ). It is the territory of WordPress Core, and as the adage goes, never modify core under any circumstances. While <code> wp-content </code> may define plugins and themes, the API itself and the vast majority of the W... | What is the wordpress wp-includes folder for? | wordpress |
I have been asked how easy it would be to have multiple contributors being able to submit content that would be brought into one post. The rub is that they wouldn't be allowed to see the main post or edit the post, this would be reserved for the site admins - their role would be mainly around adding their piece of the ... | Perhaps you could use scribu's Posts 2 Posts plugin to relate a Custom Post Type called "Drafts" (or something else to avoid possible conflict with naming conventions reserved for Post Status). It's a very powerful plugin, allows Posts to be related to other Posts. In this way you could bring in the content of the Draf... | Allow multiple contributors to one post | wordpress |
I have this code which displays images with their captions in a list. On clicking caption, opens image in an attachment page, but clicking on image, opens that image with a dark-gray background. Is there a way to display image on attachment page on clicking on it?? I played alot with it, but no success. <code> $i = 0; ... | As pointed in the other answer, you should not have prettyPhoto part The link should be changed to utilize the function get_attachment_link Basically change this line in your code <code> $link = '<a href="'.get_attachment_link($id).'">'.wp_get_attachment_image($id, $size, false).'</a>'; </code> | Change code to display image attachment page | wordpress |
I'm displaying list or archives using <code> <?php get_archives('monthly', '', 'html', '', '', FALSE); ?> </code> and my list displays December 2012 November 2012 etc However I would like to format this to display: 12.12 11.12 10.12 etc Any ideas? | There is but the filter sucks, it only gives you the link HTML: <code> add_filter( 'get_archives_link', 'wpse74891_archives_link' ); function wpse74891_archives_link( $link ) { $link = preg_replace_callback( '/>([A-Za-z]+\s+\d{4})/', function( $matches ) { return '>' . date( 'm.y', strtotime( $matches[1] ) ); }, ... | Displaying Archives List | wordpress |
I have a problem here and i cant find/think of any solution yet. I want to have a menu button that can be activated/deactivated and still keep the same id so the CSS will still be applied. Is there any plugin or a way to do that ? I allready managed to create the page and add it to menu and then remove it. That works b... | If it's all about CSS & you don't mind adding/removing it manually, please consider using a CSS class for that particular menu item. If you don't see the option, click screen options in top-right, then check the option for CSS classes. Then you can write all the CSS on this class instead of the ID. For all other op... | How to activate/deactivate menu tab and keep the same id? | wordpress |
I have a wp_query <code> $wp_query = new WP_Query($args); </code> but for some reason the <code> $wp_query->post_count </code> only shows the amount of posts on each page. So if I set <code> 'showposts' => '10' </code> and 12 results are found, page one will say '10 results found' and page 2 shows '2 results foun... | <code> $wp_query->post_count </code> is supposed to work exactly like that. To get the total number of posts that exist in the database, use <code> $wp_query->found_posts </code> | Post_count only shows the number of results per page | wordpress |
I'm building a theme to be used as an example for other websites for the company I'm working. In another project we used the Hybrid Parent Theme and was really easy to build, but REALLY hard to maintain the website. I prefer the Starter Theme approach, which another developer copy the theme and create from it. The Pare... | I totally agree with stackexchange-url ("Rarst"). I just want to add some small things. Note: I differentiate parent theme and framework. In my answer, I consider parent theme like TwentyEleven where it's mainly created for a specific website and less hooks than a framework. Starter theme: Pros Easy to customize at HTM... | Starter Theme vs Parent Theme? Pros and cons | wordpress |
I am trying to write a shortcode that works in conjunction with Contact Form 7 to display the current user that is logged in posts. I have been able to get it to work with regular posts using this code here: <code> wpcf7_add_shortcode('postdropdown', 'createbox', true); function createbox(){ global $post; $args = array... | Use <code> 'author' => get_current_user_id() </code> as an argument for <code> get_posts() </code> . This will restrict the found posts to these of the user which is currently logged in. The best reference for the available parameters is still <code> WP_Query::parse_query() </code> in <code> wp-includes/query.php </... | How to display posts by current user in a drop down | wordpress |
WordPress takes measures to ensure that a cron task doesn't run twice when it should run once, e.g. once every hour when an hourly schedule is given, rather than the occasional twice at the scheduled time. While it's not foolproof, what steps does WordPress take to make sure it happens at the scheduled times, and only ... | A transient is set to reflect the state of the cron, which gets deleted when all tasks complete. Any subsequent requests are ignored if that transient is found... | How is WP Cron Locking implemented? | wordpress |
I'm searching for some site where I can find line by line explanation of an wp theme's code. Because, I want to implement on my site just commenting area. I don't need sidebar, gadgets, searching, archives... all the toys. My page has everything I need, except commenting area, but I can't find which code lines stands a... | The Twenty Eleven Theme has some decent code comments that explain what's happening. Quick and dirty overview: All comment functionality goes in <code> comments.php </code> . You include it into your template with the aptly named <code> comments_template </code> which does a lot of stuff (sets up the current commentor,... | How to implement just the wp commenting area on my custom site? | wordpress |
I have been struggling with this for almost 2 days with no avail. I have a custom post type of <code> PRODUCTS </code> that has a group of metaboxes for uploading PDF files in the <code> wp-admin </code> . I've created the metaboxes in the admin. Here's the code for my metaboxes: <code> //PDF upload Meta Boxes $meta_bo... | Ahh I think I was able to answer this on my own. I created a variable for the $_FILES($pdf_field['name']) array and was able to use those to get the array values. Just need to do some error handling and test out my uploads. If there's something wrong with handling it this way please let me know. <code> //Upload PDF fil... | Checking if $_FILE isset for an array of file upload metaboxes | wordpress |
I am creating a blog using only Wordpress's backend. I have found functions to get latest posts (wp_get_recent_posts) and all the required data I need. I do this by including wp-load so I have access to WP's functions. However I cannot find anything that allows me to perform a search outside of Wordpress's theming loop... | You can use <code> get_posts() </code> with a search parameter: <code> $results = get_posts( array( 's' => 'search term' ) ); </code> | Search outside of the "loop" | wordpress |
I'm just learning PHP, and I'm using get_terms to get some text descriptions from the CMS, but i want to assign 3 variables to only 3 of my woocommerce tags. My code works well, but I just want to learn if there's a better way to filter by $tag_descrip-> name than using if conditions. This is my code: <code> <?php $... | Hi there is not better option, but to speed it up little you can use wordpress transient, see documentation: http://codex.wordpress.org/Transients_API your code would look like this (and i cleaned it bit and used function empty to check array...): <code> <?php if ( false === ( $tag_descrip = get_transient( 'tag_desc... | PHP Wordpress optimization my loop code | wordpress |
I'm displaying a single "featured" post at the top of the blog index page, and category pages. I'm using this conditional to display the category name of the category page if it is a category page, or to display one category title of the featured post if it is on the blog index page: <code> if( is_category() ): $catego... | By default <code> single_cat_title() </code> , a wrapper for <code> single_term_title() </code> , outputs the category name. Try replacing that call with <code> single_cat_title('',false) </code> . | Weird html output of single_cat_title - is not inside of the html element? | wordpress |
I have created a custom post type 'hotel' and custom 'taxonomy' so when administrator creates a new hotel and saves it it related custom taxonomy automatically get created but I don't want to show custom metabox in the admin side hotel edit page so for that I used WordPress function but nothing happen. My custom post c... | Change your taxonomy registration parameter <code> show_ui </code> to <code> false </code> ... <code> register_taxonomy('package_hotel','package',array( 'hierarchical' => false, 'labels' => $Package_labels, 'show_ui' => false, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'sh... | remove custom taxonomy metabox form custom post type | wordpress |
Apologies if this has been answered elsewhere, but I've had some trouble finding the solution via Google. I've set up a parent theme and a child theme. Inside the parent theme I have a directory named img which contains a number of images I want to use in the child theme too. The problem is, I can't seem to find the be... | You can use <code> <?php get_template_directory_uri(); ?> </code> to reference your parent theme folders. From the WordPress codex : In the event a child theme is being used, the parent theme directory URI will be returned... | Referencing parent theme image from child theme | wordpress |
I'm trying to add a div to a widget's content in my dynamic sidebar. Here is the register code; <code> register_sidebar(array( 'name' => "Sidebar1", 'id' => 'home-sidebar-1', 'before_widget' => '<div class="sidebar-box">', 'after_widget' => '</div>', 'before_title' => '<div class="title"&g... | In addition to Toscho's answer here's what you need for a robust solution: <code> // if no title then add widget content wrapper to before widget add_filter( 'dynamic_sidebar_params', 'check_sidebar_params' ); function check_sidebar_params( $params ) { global $wp_registered_widgets; $settings_getter = $wp_registered_wi... | Adding a div to wrap widget content after the widget title | wordpress |
How do you add a new class to the HTML generated when an image with captions is added? For example, from this: <code> <div id="attachment_xyz" class="wp-caption alignleft"... </code> to this: <code> <div id="attachment_xyz" class="wp-caption alignleft my_new_class"... </code> Adding, in this case, my_new_class . ... | Adapted from stackexchange-url ("this answer") Add this code to your functions.php file: <code> add_action( 'after_setup_theme', 'wpse_74735_replace_wp_caption_shortcode' ); /** * Replace the default caption shortcode handler. * * @return void */ function wpse_74735_replace_wp_caption_shortcode() { remove_shortcode( 'c... | Add extra class to wp-caption? | wordpress |
I have a custom field on a category where you can add an image. I have it as a background image to show on the category's archive page, like so: archives.php <code> <body style="background:url('<?php echo z_taxonomy_image_url($cat->term_id); ?>')"> </code> It uses the Categories Images plugin to achieve ... | You can use this function to output the parent category ID and then style off of that. <code> <?php function wpse_74737_category_top_parent_id($catid) { while ($catid) { $cat = get_category($catid); $catid = $cat -> category_parent; $catParent = $cat -> cat_ID; } return $catParent; } </code> And then call this... | Post to inherit custom category background image from parent | wordpress |
The site I'm working on will have a very large number of unique user roles via a members plugin. Because of that, I'd like to have the Role drop-down selection on the Add New User page to display roles alphabetically, rather than descending order of creation. Is there any way to do this? | Almost the same approach One Trick Pony has chosen, but I am using translated names and <code> uasort() </code> (to preserve the keys): <code> add_filter( 'editable_roles', 't5_sort_editable_roles' ); /** * Array of roles. * * @wp-hook editable_roles * @param array $roles * @return array */ function t5_sort_editable_ro... | alphabetically order role drop-down selection in dashboard | wordpress |
I'm familiar with password protecting files and directories using apache authentication. I am working on a site where I have two WordPress installs on the same domain. One WP install is in the root /public_html/ another one is in a sub directory. We do NOT want to merge the user database this is why we are using separa... | Ok guys, I did further research. Basically, all I had to do was add "Satisfy Any" argument. So the main .htaccess file looked like the one I posted in my initial thread. Then for the specific folder, I created a new .htaccess file (/folder/.htaccess). Then added this: <code> <Files wp-login.php> Satisfy Any </... | What's the opposite of required valid user in .htaccess authentication | wordpress |
I'm trying to upload a PDF file for a custom post type called <code> Products </code> using <code> wp_upload_bits </code> . I'm only doing this in my wp-admin. I don't want these files added to the media library, I just want to upload them and return the URL for when I display the Product. However when I do I get the e... | Ahh I figured it out. After echoing and print_r every single thing I could I figured out that this line: <code> $uploaded_file = wp_upload_bits($_FILES[$pdf_field['name']], null, file_get_contents($_FILES[$pdf_field['tmp_name']])); </code> Needed to be changed to this: <code> $uploaded_file = wp_upload_bits($pdf['name'... | Invalid file type when using wp_upload_bits to upload PDF to a custom post type | wordpress |
I am using nice SMCF ( Contact Form ) want to add a wordpress post list Drop Down menu in "Simple Model Contact form" here what i added on line '195' to try look. <code> $output .= "<div class='colmsg'><label for='smcf-message'>*" . __("Message", "smcf") . ": </label> <select name=""> <option... | It just wasn't concatenated correctly (i.e. misuse of single/double quotes). This'll work: <code> $output .= '<div class="colmsg"><label for="smcf-message">*' . __("Message", "smcf") . ': </label> <select name=""> <option>Post1</option> <option>Post2</option> <option&g... | Add Input Field in Simple Model Contact Form (smcf) plugin | wordpress |
I am allowing users to query posts using a form with checkboxes. I want the posts to be filtered by the checkboxes but instead of showing all posts that include the ANY of the meta values selected I want to show posts that contain all of the selected values. Is this possible? Here is what I currently have using the "IN... | You can have multiple <code> meta_query </code> arguments with the same key and that will produce the results you're seeking. Here's an example: <code> $meta_query = array_map( create_function( '$a', 'return array("key" => "row_amenities", "value" => $a);' ), $amenities ); $the_query = new WP_Query(array( 'post_t... | WP_Query meta compare must include ALL array values | wordpress |
I have a custom post type of products that I've setup to upload PDF's using metaboxes. When I generate the metaboxes on the wp-admin, I look to see if the metabox already has a pdf uploaded to it or not. If it DOES I generate a link to the pdf. If it doesn't I generate a file upload control where they can pick a file t... | You are searching for Ajax. This Q&A may give you an idea: stackexchange-url ("Unattaching images from a post"). There are many specialists on the matter here at WPSE, check this stackexchange-url ("search query"). | Add a button or image button that calls wp functions in the wp-admin | wordpress |
Images are there, but they don't always show up. Could this be a cache problem? Or Timbthumb? Here is an example: http://designportugal.net/servicos/design/ And another: http://designportugal.net/portfolio/#all/3/list I sometimes also have trouble getting into WP dashboard, it gives a warning php error, but when I refr... | If I visit your first link and look at the response, I get a <code> 500 Internal Server Error </code> when trying to get the following resource: <code> http://designportugal.net/wp-content/themes/dt-nimble/timthumb.php?src=/wp-content/uploads/2012/11/drpedrocoelho.png&zc=1&w=30&h=30 </code> so my guess is t... | Cache issues with images not showing up | wordpress |
I have this plugin that displays category featured image thumbnails for each post via shortcodes.. like so, <code> [categorythumbnaillist 3] (3 being the category of course) </code> I would like it to only show posts with the tag "news".. only if you set the tag value to "news" via the shortcode. So if you entered in..... | That plugin you have is not using the WordPress Shortcode API as it should be. There is not a single <code> add_shortcode </code> to be found. It has basically cooked up its own shortcode 'feature' by hooking a <code> preg_replace_calback </code> into <code> the_content </code> <code> define("categoryThumbnailList_REGE... | Adding a Tag Parameter / Filter to My Shortcode | wordpress |
I want to list all the values of a custom metabox in a custom post type. Here is the code to get the one meta box in a single post <code> <?php echo get_post_meta($post->ID, 'institution_location', true);?> </code> but say I want to list all the meta boxes in the home page or a dropdown menu in a search form n... | I tried to use WP_Query and it works fine. <code> <?php $args = array('post_type' => 'institution'); $the_query = new WP_Query($args); while ( $the_query->have_posts() ) : $the_query->next_post(); $id= $the_query->post->ID; $location = get_post_meta($id, 'institution_location', true); echo $location; ... | Get all meta boxes values | wordpress |
I've included the javascript by <code> wp_enqueue_script('slider', plugins_url( 'slider.js', __FILE__ ) ); </code> with just a simple <code> $(document).ready(function () { alert("alert"); }); </code> It shows up in the browser but doesn't prompt me with "alert". PS: Forgot to mention I've also included the jquery, but... | A few things: The version of jQuery that ships with WordPress is run in noConflict() mode. Meaning you have to use <code> jQuery </code> instead of <code> $ </code> when you make your first reference. Don't register your own version of jQuery when you're developing. You're locking yourself in to a single version that m... | Javascript included but alert() function not working | wordpress |
I'm trying to display multiple feeds using the fetch_feed function. Its working well thus far except I can't figure out why the title for each individual rss feed will not show up. Here is my code: <code> <?php // Get RSS Feed(s) include_once(ABSPATH . WPINC . '/feed.php'); $rsslist = array( 'http://www.lt11.com/rss... | I don't see anything to suggest that <code> fetch_feed </code> is supposed to accept an array of values. That is not mentioned in the Codex, nor the source, <code> @param string $url URL to retrieve feed </code> . That said, <code> fetch_feed </code> passes things off to SimplePie's <code> set_feed_url($url); </code> w... | combine multiple feeds with fetch_feed and display blog titles for each item? | wordpress |
With this line everything works fine - (as a Non-Wordpress index.php): <code> <link href="style.css" rel="stylesheet" type="text/css"/> </code> When I activate the file as a wp theme and replace above line with: <code> <link href="<?php bloginfo('stylesheet_url');?>" rel="stylesheet" type="text/css"/>... | images folder is inside theme's folder. But relative URLs do not work that way. They are relative to the URL not to the filesystem path. Your problem is here: <code> <img id="thinker01" src="images/thinker01.png" width="120" height="163" /> </code> If you look at the request (via HttpFox or other means) you will ... | I have no images in an activated wp theme | wordpress |
I have this structure for my categories: <code> Issue 4 - News - Supporting our troops - Breaking news <?php $category = get_the_category(); $parent = $category[0]->term_id; ?> </code> This code gets the top level category ID from "Breaking News" which is Issue 4, missing out News its direct parent category. H... | You need to use <code> get_ancestors() </code> . Assuming your post is only in one category, the following code should work (if it's in multiple you'll need to loop through each of the assigned categories to determine the various hierarchies). <code> $category = get_the_category(); $ancestors = get_ancestors( $category... | Get 1st parent category id from post | wordpress |
I'm running multisite with each subsite using the same custom theme. I'm using NHP Options for logo upload and contact page info changes in that theme. I'd like to add a site list page to the main site (which is using a different theme) and have each subsites logo be displayed beside its name in the list. Getting the s... | may be its a late reply, but i hope this code will help you and anothers to solve this problem. <code> <?php global $wpdb; $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' AND blog_id != 1 "); $sites = array... | Multisite - Retrieve the same theme option from all sites of the network | wordpress |
I would like to identify admin users and non-admin (but logged in) users through cookies. I need this feature because I use Hyper Cache (which uses cookies to identify those who send pages in cache): I would like to serve cached page to all users not logged in and to all users logged in but non-admin. The logged in adm... | You can use <code> current_user_can() </code> to detect what type of user is logged in, if any, then use <code> setcookie() </code> and <code> $_COOKIE </code> to test and set the necessary cookies. <code> function wpse_74742_stop_cache_cookie() { if (current_user_can('admin')) { if (empty($_COOKIE['disable_cache'])) {... | How to set different cookies for logged in admin users and logged in non admin users? | wordpress |
All of my products on my site are $1 and during an import I did using WooCommerce import it didn't save all the _regular_price & _sale_price values, so there is no way for the user to buy that product. Is there a mysql query that can go through and apply a value to all of the nulls to the $1 value? | Looks like you are not familiar with WordPress Bulk Edit . Change the <code> Screen Options </code> to show all the products you have (if there are too many this can be slow, and is better to do it following some 100/200 product per page). Select all the products, select <code> Edit </code> in the Bulk Edit dropdown an... | Defining the same price to all WooCommerce Products | wordpress |
I want to have a sticky post for all my pages and categories. The choice of "sticky post" in the edit post, didn't work. I found many pieces of code but I haven't the result that I want. I prefer to implement coded and not with a plugin. Any help? Thanks in advanced. | <code> $sticky = get_option( 'sticky_posts' ); $args = array( 'posts_per_page' => 1, 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ); query_posts( $args ); if ( $sticky[0] ) { // insert here your stuff... } </code> | Sticky post for all pages and categories | wordpress |
I'm currently trying to log into a WordPress website, which I downloaded off the virtual server, now in my local server (MAMP, because I'm on a Mac machine). When I try and log into the backend, it successfully gives me the WordPress login screen. After I log in with the correct credentials, it gives me the following: ... | It sounds like you did not correctly move WordPress and your local install is trying to login to the hosted site. I am guessing that this is the problem becasue of this sentence, "Data may not be posted from offsite forms." Your login form should not really ever be "offsite". You need to change the site URL just as if ... | HTTP Error 403 When Trying to Login | wordpress |
I'm looking to organize a large WordPress Movies/Actors site, with thousands of posters, screenshots, etc... I currently have the images in a directory structure like /actors/firstname_lastname/filename1, etc.. with a database matching each pathname with a movie. Some names may have thousands of images. I suppose I wan... | I would not do it post by post I would use a plugin so I can manage it more and present them in lightbox or as a gallery. Plus in the future if you want to blog or add news you can always use the posts for that. Nextgen Gallery has been around for some years and I manage tons of photos and I can export and import pics ... | Large Media Library | wordpress |
I'm looking for a definitive answer here. When object caching is enabled, where do options and transients end up living? By default, both are stored in the database. But I've heard some references that memcache will store them elsewhere and APC will do something else entirely. Where, exactly , will this data be persist... | WordPress, by default, does a form of "Object Caching" but its lifetime is only a single page load. Options are actually a really good example of this. Check out stackexchange-url ("this answer") for more info. The summary: A page starts All options are loaded with a simple <code> SELECT option_name, option_value from ... | How does object caching work? | wordpress |
Fighting to create an ajax request. I've been reading couple of articles but still I can't get my plugin to send and recive ajax datas. first init the js <code> function ajax_load_scripts() { // load our jquery file that sends the $.post request wp_enqueue_script( "ajax-calls", plugin_dir_url( __FILE__ ) . '/assets/js/... | If you need to use the WordPress enviorment and functions in your ajax processing funciton then you need to post/get your AJAX request to admin-ajax.php, So change <code> 'ajaxurl' => plugin_dir_url('my_plugin.php') </code> to <code> 'ajaxurl' => admin_url('admin-ajax.php') </code> | where do I send my ajax calls | wordpress |
I want to add custom image sizes to the media uploader: In order to do this, I use the following code (comments are there for convenience): <code> // this function adds the custom image sizes to the media uploader function my_insert_custom_image_sizes( $sizes ) { // get the custom image sizes global $_wp_additional_ima... | <code> Invalid argument supplied for foreach </code> means that the X in <code> foreach X as ... </code> is not an array. You can prevent this error by type casting; add <code> (array) </code> before the argument in the foreach statement. This will turn your variable into an array, essentially. In your code, the change... | Add custom image sizes to media uploader | wordpress |
I'm using the theme options page from the underscores (_s) theme to build a theme options page and I have a group of check boxes on it. In the example below I've just included 2 for simplicity. My questions are: What goes in the checked() function below to keep each check box checked when saved? I have to check each va... | So checked is fairly simple to understand. It compares the first two values. If they're equal, it spits out <code> checked="checked" </code> if they aren't equal nothing happens. <code> <?php $saved = 'on'; $compare = 'on' // spits out checked="checked" checked($saved, $compare); $saved = 'off'; // does nothing chec... | How to use checked() function with multiple check box group? How to properly sanitize that checkbox group? | wordpress |
I'm trying to add a screen option to the dashboard screen. I have a function like: <code> my_function() { ... add_screen_option() ... } </code> Now, I need to know the correct action hook $hook to use hooking in my function when the dashboard screen is loaded: <code> add_action( "load-$hook", 'my_function' ); </code> W... | <code> add_action( 'load-index.php', 'the_function', 1, 0 ); </code> The <code> load-{page_hook} </code> hook works with the filename of the page to load. | load-* hook for dashboard | wordpress |
I'm working on a wp project with responsive theme. I have single level nav menu at the top of the site, that I want to change to a Select Option tag for mobile browsers (small screens) with options for the nav items which is much easier to select in mobile site. So the UL LI menu will be replaced with a Selection- Opti... | Here's what I've put together from different articles/themes: files to modify: functions.php header.php style.css js (create folder "js" in theme root directory) The Javascript: <code> jQuery(function() { jQuery("<select />").appendTo("nav"); jQuery("<option />", { "selected": "selected", "value" : "", "tex... | Convert WP Menu to a Drop Down for Mobile browser | wordpress |
I am using a plugin wordpress-simple-paypal-shopping-cart for my cart requirement. I am trying to send an email through this plugin when some payment is made by using IPN. My code : <code> $invoiceProducts = $_SESSION['simpleCart']; if(isset($invoiceProducts) && !empty($invoiceProducts)){ $html = renderHTML($in... | <code> wp_mail() </code> is defined in <code> wp-includes/pluggable.php </code> . This file is loaded after the plugins are loaded, but before the hook <code> plugins_loaded </code> has been fired. So the answer is: wait. <code> add_action( 'plugins_loaded', 'renderHTML' ); </code> On a side note: prefix your function ... | Fatal error: Call to undefined function wp_mail() | wordpress |
Or, how is the admin_bar displayed at all? I'm looking to display a similarly styled menu, but for all users who visit. | I believe you are talking about the admin_bar which has many hooks. You can read more about wp_before_admin_bar_render and wp_after_admin_bar_render in codex and actually wp source. | What hook is used to display the admin_bar on the front end? | wordpress |
If I install WordPress on my server, does it mean that Akismet is installed automatically? If so - do I still need to create e-mail verification and captcha tools for improving site security (as I see WP does not have this features in itself). What is recommended for captcha test- simple php captcha or some graphical a... | Akismet comes pre-installed with WordPress. You will, however, need to activate it from the 'Plugins' menu and sign up for an API key (free plans are available). And no, captchas are not needed (Akismet catches almost everything), but you can find a plugin to add one if you wish. If you're concerned about sercurity, I ... | About WordPress site security | wordpress |
I just moved to a dedicated server and I was wondering whether i need to do anything explicitly inside wordpress config files to increase the performance of the site, like setting an upper memory limit.. is this really needed? many thanks, Andy | Actually, you should take advantage of your server and move some of the load from the database (usually disk) to the memory. You could start by enabling the APC PHP extension and installing this plugin. | PHP Memory Limit Question | wordpress |
As new user to wordpress I'm finding that the preset templates structure a little restricting coming from the flexibility of other template routed CMS I've worked with. Saying this, I know there are plenty of workarounds and I'm now currently in the process of trying to establish them. -- One of the main hurdles I'm fi... | Mobile might not be a great example -- responsive design would take care of that. Were this my project I would take a slightly different approach. Instead of prefixing the URL, I would stick the mobile on the end with an rewrite endpoint. An endpoint combined with using the <code> template_include </code> filter would ... | Multiple templates for a custom post type | wordpress |
I have this idea for linking to a paragraph within a post. It would work by every paragraph within <code> the_content() </code> on post pages having an anchor tag automatically placed before it, like this: <code> <a href="#p1"></a> </code> where '1' is the first paragraph and it would increment for every su... | I think that should really be <code> <a name="p1"> </code> around the paragraphs with link to the paragraphs being <code> <a href="#p1"> </code> . If that is what you are trying to accomplish ( what used to be called a named anchors ), that technique is not valid in HTML 5. You can instead link to any <code... | Automate paragraphs in a post page to have a unique anchor link | wordpress |
Is it possible to have the site title prepended before each post title, separated by a hyphen? For example: <code> [my site title] - [my post title] </code> | <code> function prepend_site_name($title) { return get_bloginfo('name').' - '.$title; } add_filter('the_title','prepend_site_name'); </code> Like that? | How to display site title with post title? | wordpress |
WordPress has an option to pick "Latest Posts" and "Static Page" under "Settings" in Admin Panel. My questions: What page template is getting loaded in each of those modes? Why <code> paged </code> stops working and <code> page </code> starts working when I select "Static Page" - <code> paged </code> works, however, wh... | Conditional Tags The <code> is_front_page() </code> Conditional Tag returns <code> true </code> if you're on the Front Page ( <code> index.php </code> as fallback or <code> front-page.php </code> ). The <code> is_home() </code> Conditional Tag returns <code> true </code> if you're on the Front Page, when you got no sta... | What are the differences between "Latest Posts" and "Static Page"? | wordpress |
I have a Bakery page. Every time I add a child page such as cakes, I would like to add the page title <code> cakes </code> to a custom taxnomy. I also want to add this child page to a menu which displays these child pages. I have found out that I need to hook into the <code> new_page </code> . So something like this, <... | I agree with @brasofilo that this is two very different questions, but I think we can answer both here. 1. Automatically add child pages of A to custom taxonomy B's term C. We'll add the term 'yummy' in the custom taxonomy 'food-adjective' to all child pages of page ID 123 when they're published . You can add this to y... | How can I make this process automatic? | wordpress |
How am I blocking certain pages from being viewed by logged out users? I have some pages like a dashboard for example that each user has to display their posts an is found in the top level like mysite.com/dashboard. I made a custom template and assigned it to the page "dashboard" but I need to block all non logged in u... | You have to hook in earlier, I would probably use <code> template_redirect </code> : <code> add_action( 'template_redirect', 'wpse_74577_redirect' ); function wpse_74577_redirect() { // the code from your question } </code> | block a page from logged out users and redirect to homepage | wordpress |
I made a custom search form with select boxes and text fields. I have a select box with options like "renting" and "selling" (its a real estate site) There are also input fields for minimum and maximum price, for location etc. In the posts I have custom fields for all those filters. I used WP_Query for that. And it sho... | The way you have built that query it is possible for you to have a bunch of empty values. For example, if <code> grad </code> is not present then you end up searching <code> ex_lokacija </code> keys for empty strings. Since your main relation is <code> AND </code> all of the terms have to 'hit' so it seems likely to me... | Using WP Query to search by multiple meta fields | wordpress |
Finally I finished to write my widget, and now want to call it using function inside themes php files. My widget looks like this: function reg_custom_widget() { register_widget('wp_custom_widget'); } class wp_custom_widget extends WP_Widget { function wp_custom_widget() { /* constructor */ } function widget($args, $ins... | Using <code> the_widget() </code> is the correct way to "hard code" an arbitrary Widget in a template file: <code> <?php the_widget( 'foobar_widget', $instance, $args ); ?> </code> Since <code> the_widget() </code> simply returns if <code> 'foobar_widget' </code> is not a registered Widget, it is functionally equ... | Calling widget via function in themes files (hard code) | wordpress |
It it possible to get the configuration of a the latest called WP_Query? I need to use it for debugging. For example, if i run something like: <code> $the_query = new WP_Query( $args ); ... </code> Could i get the $args array later by doing something like <code> $the_query->args(); </code> or something? | Try the <code> $query_vars </code> property : <code> $the_query = new WP_Query( $args ); $query_arguments = $the_query->query_vars; </code> Which should return an associative array of query variables. To test: <code> var_dump( $query_arguments ); </code> | Get WP_Query query after execution? | wordpress |
I want to restrict users from deleting posts permanently. How do I restrict access to the Trash folder in Posts? This is the only page were the users can delete their posts permanently . The only solutions that I have so far is: 1) Adding this to stylesheet: <code> li.trash { display: none; } </code> But both me and yo... | With the filter we prevent the <code> Trash </code> link from being printed. And with the action, redirect back to the post listing page if the user tries to access the URL directly ( <code> /wp-admin/edit.php?post_status=trash&post_type=post </code> ). <code> add_filter( 'views_edit-post', 'wpse_74488_remove_trash... | Restrict access to the Trash folder in Posts | wordpress |
I'm using the Advanced Custom Field plugin - although I'm not positive that is relevant. Nonetheless, I can't get substr() to work at all using this method: <code> $givchars = 5; $postgiv = the_sub_field('get_involved_text'); $modgiv = substr($postgiv, 0, $givchars); echo ' ' .$modgiv. ' '; </code> However substr() doe... | It looks to me like <code> the_sub_field </code> echoes content. It is never returned for <code> substr </code> to work on. You need <code> get_sub_field </code> . <code> $givchars = 5; $postgiv = get_sub_field('get_involved_text'); $modgiv = substr($postgiv, 0, $givchars); echo ' ' .$modgiv. ' '; </code> | Truncating characters in Advanced Custom Fields works some places but not others? | wordpress |
I've setup an "album" custom post type and want to add an icon on the index page where the RED circle is (see image below; from wptheming.com). Here's my function to replace the icon. The CSS is what I found when I inspected the icon element with firebug: <code> add_action('admin_head', 'album_foo'); function album_foo... | I figured it out! When WordPress looks for the 32x32 icon on custom post index/edit/add pages, it starts by looking in: <code> /wp-admin </code> because that's where the WordPress 32px icons are located. But CSS references are usually relative to the location of your stylesheet. So when adding the location of your icon... | Add 32x32 icon to custom post type index page | wordpress |
I'm building a single template right now for a custom post type. I'm wondering if there is a way to check if either at least one or multiple of the custom values has been entered so I can display the div accordingly. Basically, I want to display the div it has anything filled out, if it is left blank then don't show it... | Since you already using <code> get_post_custom </code> a slightly cleaner yet still dirty (php) way of doing it. <code> $sermondata = get_post_custom($post->ID); if( isset($sermondata['sermon_audio']) || isset($sermondata['sermon_video']) || isset($sermondata['sermon_document'])) { ?> <div id="downloads"> /... | Check IF single OR multiple custom data has been entered | wordpress |
› Moderator Notice ‹ This question exists as it fills a specific criterion and/or has historical significance. The current answers do not work for current WordPress versions. If you got a working solution, please add it as a new answer. If you got the exact same question, you could offer a bounty to attract working sol... | There's a filter called <code> media_upload_default_tab </code> that you can use to do this. <code> <?php add_filter('media_upload_default_tab', 'wpse74422_switch_tab'); function wpse74422_switch_tab($tab) { return 'library'; } </code> You can set the to be whatever -- assuming the tab exists. The tab keys themselve... | Changing the media library default tab | wordpress |
I know it's possible to setup a CDN with W3 Total Cache for cached content. However, how would I setup a CDN with WordPress to initially upload all media content (images, videos, files, etc.) directly to the CDN instead of my web host/local install. I'd like to completely bypass uploading content to my hosting account ... | To totally bypass WP, just use the CDN native interface or a utility like cyberduck to upload you files directly to the CDN and embed the file from the "From URL" tab at the add media thing. This can work with files and video but will be problematic with images as WP process images to create thumbnails and gather EXIF ... | How to Setup a CDN for All Content? | wordpress |
I'm making a site based on WordPress. It's not going to seem a blog or WP. Just a website. So WP acts like backend where the client can edit the text blocks. Question: How can I put block of text on my designed template wich users can edit from admin panel? Let's say something like this: The 3 top blocks (about us, mis... | You have multiple options here, depending on the amount of flexibility you want to give the editor of the text blocks. Create a custom loop with <code> WP_Query </code> . See stackexchange-url ("our examples") and the Codex page for usage. Then you print the excerpts of the page these boxes are linked to. You can use a... | How to Create Editable Blocks of Text for the Homepage? | wordpress |
I'd like to change only one output of native WP Gallery (in media.php) On Smashing Magazine ( link ) author advises to change whole gallery_shortcode function. But I wondered if is possible to change only specific output ($captiontag) I wrote: <code> add_filter( 'captiontag', 'my_captiontag' ); function my_captiontag( ... | There are no filter hook called <code> captiontag </code> . You can change the value of the caption html tag by specifying the <code> captiontag </code> option when inserting the <code> [gallery] </code> shortcode. From the gallery shortcode codex page : captiontag the name of the XHTML tag used to enclose each caption... | add_filter and changing output captions of image gallery | wordpress |
Is there a page somewhere that details exactly how WordPress generates slugs for URLs? I'm writing a script that needs to generate URL slugs identical to the ones WordPress generates. | Off the bat, I can't give you a page/tutorial/documentation on how WP slugs are generated, but take a look at the <code> sanitize_title() </code> function. Don't get a wrong impression by the function name, it is not meant to sanitize a title for further usage as a page/post title . It takes a title string and returns ... | How does WordPress generate URL slugs? | wordpress |
While adding images in a post with the gallery shortcode, I want to display an image number as title of the image e.g if there are 3 images in a gallery and displayed as a list, above each image there should be a serial number. Shown as I can set it afterwards with inline css. I tried alot in <code> media.php </code> ,... | Set a custom function between the gallery shortcode handler and the output. Catch the <code> img </code> elements and add a static counter. Then return the gallery output to WordPress. Sample code: <code> add_action( 'after_setup_theme', 'wpse_74492_replace_gallery_shortcode' ); /** * Replace the default shortcode hand... | Numbering Image List in Gallery | wordpress |
I need to find out what happend at certaint time when some of my admins make some plugin updates etc. So i need to check in admin the log of changes, updates etc. Where can I find that in WP admin? | You can't pull it in wp-admin you actually have to go look at the plugin in wordpress repository and see if they added there or to the plugin author's site for a changelog. That would be a nice feature for the future. | Where in WP can I check history or log of updates of plugins etc? | wordpress |
I have installed a plugin, but it causes problem with get_the_excerpt() function in my theme. So, I need to downgrade that plugin. How to do that? | If that plugin is hosted on wordpress.org, go to the plugin page, click on the developers tab, and select an older version. Example for JetPack . | How to downgrade plugin? | wordpress |
I have one page that I need to change the URL for. Currently, the page resides at example.com/departments/human-resources/ (human-resources is a sub-page of /departments/ ) My client wants to maintain the legacy url for the hr department which is: http://example.com/hr/ How can I rewrite any request for <code> ^/hr/?$ ... | Redirection allows you to modify post slugs and keeps a history of them, pointing all requests for the history of a page to the same destination. It's useful for all sorts of other things too, but it will definitely solve this problem. | a one-off rewrite rule | wordpress |
I am doing a special migration from someone's custom CMS to a WP installation. I successfully got the posts and comments migrated into their respective tables. Now I need to get the comment count into the wp_posts table for each matching id. I have something like this. I'm close, I think: <code> SELECT COUNT(comment_co... | And I finally figured it out. For those who want to know how something like this is handled with MySQL, here it is: <code> UPDATE wp_posts, (SELECT COUNT(comment_content) AS total_comments, comment_post_ID FROM wp_comments GROUP BY comment_post_ID) x SET wp_posts.comment_count = x.total_comments WHERE wp_posts.ID = x.c... | How to update wp_posts with just the returned comment count from wp_comments (SQL GROUP BY) | wordpress |
Is it possible to validate PHP code? I have a Custom Post Type (Film) with Custom Meta Boxes. Everything is working fine, I can add new Films and details to the Custom Meta Boxes. My problem is with the Update button. If I create a new film, add info and click Update a get a white screen. I know the problem is with the... | Your code works just fine on my end. So, I'd say your problem is elsewhere. Troubleshooting guide . You can use standard debugging or stackexchange-url ("FirePHP"). I also use the following for cases where FirePHP doesn't display information, i.e., <code> save_post </code> . <code> function my_log( $msg, $title = '' ) ... | How to Debug the 'save_post' Action? | wordpress |
I would like to exclude categories from my homepage, but I want them to still display in the sidebar shown on the homepage, how can I do that? At the moment my code excludes from both the content area and the sidebar, and I am putting the code in the functions.php file: <code> function exclude_category_home( $query ) {... | You may have to alter the loop on the homepage. Set it up in your index.php: <code> if ( is_home() ) { query_posts( 'cat=-5,-34' ); } </code> and you should be good to go. | Exclude categories from homepage but not from sidebar | wordpress |
I wonder if it's possible to do a shortcode only in another shortcode . For example I got following code pieces: <code> [heading]some pricing page[/heading] [pricing_box] [heading]Some title[/heading] [/pricing_box] </code> Now I don't want to define one shortcode heading which would apply to both the nested one and th... | To use a different callback for the nested headings switch the shortcode handler in the <code> pricing_box </code> callback and restore the main handler before you return the string. <code> add_shortcode( 'pricing_box', 'shortcode_pricing_box' ); add_shortcode( 'heading', 'shortcode_heading_main' ); function shortcode_... | Execute shortcode only in another shortcode | wordpress |
I'm trying to add a conditional that will display a default image if the "image" field isn't populated... here's what I'm trying to work with: <code> $args = array( 'posts_per_page' => 3, 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'is_featured', 'value' => '1', 'compare' => '!=', //... | I finally got this working - thanks everyone for the feedback, with that I was able to rethink things a little and figure out a solution that does just what I wanted it to :) Here it is (also filtering through tags to get related posts): <code> <?php $tags = wp_get_post_tags($post->ID); $tag_ids = array(); foreac... | How do I add a nested conditional within an echo - to use a default image if there isn't one in the post? | wordpress |
I am in need of re-posting random posts to the front page of the blog to make them fresh. Is there any hook that could help me achieve it? Thanks. | You may use the Old Post Promoter plugin: http://wordpress.org/extend/plugins/old-post-promoter/ This plugin promotes old posts by sending them back onto the front page and into the RSS feed. It does it randomly choosing an eligible post and updating the publication timestamp. The post then appears to be the latest pos... | How to re-post an old post? | wordpress |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.