INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Is it possible to get all term items from a custom taxonomy regardless of post attachment status? Essentially, I build web sites with galleries, for photographers. Up until now, gallery images have all been attached to posts and I've just pulled from the category taxonomy. This is messy if it's also to be used as a regular blog. So I've been poking around and I discovered things like if an attachment item isn't assigned to a post, it has a `parent_post ID` of **0**. If I could, how would I go about simply getting all items with a term in my custom taxonomy, ignoring their `parent_post IDs`? I'm getting the feeling Wordpress just isn't quite there yet, for what I would like to do...
If I understand right, you need all attachments (attached or not) with specified term? $args = array( 'post_type' => 'attachment', 'my_taxonomy' => 'my_taxonomy_term' ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ): while ($my_query->have_posts()) : $my_query->the_post(); // your stuff here endwhile; } // Don't forget to reset wp_reset_postdata(); WP_Query Taxonomy Parameters.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom taxonomy, advanced taxonomy queries" }
new WP_Query all post in a category inside the loop Im trying to get a list of post in a category with this: $category = get_the_category(); $args = array( 'post_type' => array('post', 'entrevista'), 'cat' => $category[0]->term_id, 'post__not_in' => array(get_the_ID()), 'ignore_sticky_posts' => 1, 'posts_per_page' => -1 ); $queryScience = new WP_Query( $args ); unset($args); ?> <?php if ( $queryScience->have_posts() ) : while ( $queryScience->have_posts() ) : ?> <option value="<?php echo get_permalink($queryScience->post->ID); ?>"><?php echo ucwords(get_the_date('M Y', $queryScience->post->ID)); ?></option> <?php endwhile; endif; wp_reset_query(); wp_reset_postdata(); ?> I think it goes infinity loop because shows more than 40.000 results. What am I doing wrong?
You have to call `the_post()` within your loop, otherwise you'll output the first post in an infinite loop, as `have_posts()` will always be true. $queryScience->the_post(); Also, you don't need `wp_reset_query()` with `WP_Query`, `wp_reset_postdata()` is enough.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, loop, list" }
Is it possible to animate the Twenty Eleven menu? I have a menu in my Twenty Eleven child theme that has some hierarchical items. Twenty Eleven handles it just fine, of course, but my client likes the fancy-looking menu animation that you can see on this site. I don't need the horizontal style that shows up under the "Resources by Topic" item, just the on-hover expansion like the "Who We Are" heading. I have used jQuery quite a bit before in other (non-WordPress) websites, but don't know where to begin in this case. Is this animation possible with Twenty Eleven?
The answer is yes. It is possible with some jquery. I think your question is still too broad. Also, asking for plugin recommendation is on the don't ask list. Id start doing some Google searches for implementing jquery in a wordpress menu, attempt and maybe ask for help with your code if it is not working. Otherwise a quick search for wordpress menu plugins will give you lots of addon choices.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -3, "tags": "menus, jquery, theme twenty eleven" }
How to insert link to the default post archive into a menu I can add categories, I can even add a custom post type archive, but I can't add the original posts archive. It's not among the page list. I worked around this by creating a page, creating a page-pagename.php file, displaying the posts there and linking to that page, but when that page is shown, the menu item doesn't have the 'current-menu-item' class.
Instead of finding out how to put a custom archive link in the menu (which would still be nice to know), I found the problem with my custom page template solution. To display the posts in the News page template I obviously had to alter the original query, which carried the News page record. Since the footer, which was outputting the menu, only came after the loop, it couldn't find out which page it was on - hence it couldn't correctly assign the current-menu-item class. All it took was a `wp_reset_query();` command after the custom loop and we're good.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "menus" }
Name and password development/offline mode plugin I have found this: < But, I need something a little different. Something like Jommla has for off-line mode e.g.: < But I need to be able to access the frontend and NOT ONLY THE BACKEND!
If I understand it correctly, you're trying to restrict access to your site while you're building it. So visitors not logged in see some sort of maintenance mode page, while logged in visitors can access the dashboard and see the front-end while they develop? I think your best route is to use a plug in. There's several available for free on WordPress.org. I found this one that looked promising and has had regular updates..
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "offline" }
Is it possible to change the log file location for WP_DEBUG_LOG? I use WP_DEBUG_LOG in my development environment and have no issues with debug.log being in the wp-content directory. Sometimes I turn on WP_DEBUG in production when I need to debug something, and I still want to use the log but would like to redirect it to something outside my web root. Is this possible using WP_DEBUG_LOG?
It turns out that all WP_DEBUG_LOG does is: ini_set( 'log_errors', 1 ); ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); So, if you want to change the log location for WP_DEBUG_LOG in a plugin or theme, webaware's answer is best. If you just want to have it changed within `wp-config.php` you can replace `define( 'WP_DEBUG_LOG', true );` with the above 2 lines and change the log file to wherever you want.
stackexchange-wordpress
{ "answer_score": 21, "question_score": 27, "tags": "debug, wp config" }
How to disable commenting from Twenty Ten theme? This is a terrible user experience when I'm trying to do the most simple thing and it never works. There are many pages with "instructions" how to do this and none of the "instructions" work. Now we hate Wordpress for making the most simple thing just not possible. ## Solution ## This only worked when doing it via the quick-edit which is disastrous since there no instruction that says so. We should get our money back for this crap.
WordPress admin screen -> Settings -> Discussion -> "Allow people to post comments on new articles". Uncheck it. For existing posts, go to Posts -> All Posts. You can click "Quick Edit" on any post to find the "Allow Comments" checkbox and turn them off for that post. To bulk-edit existing posts, you can select all the posts you want to edit at once using the checkboxes, then use the "Bulk" feature at the top of the page. Select "Edit" from the dropdown, click Apply. Then in the bulk editor, change the Comments dropdown to "Do not allow" to change that setting on all the selected posts. This applies to _any_ theme, it is not specific to Twenty Ten.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -7, "tags": "theme twenty ten" }
How to modify the paths of js from twentytwelve theme? `<?php wp_head(); ?>` from my default wp theme generates <script type='text/javascript' src=' <script type='text/javascript' src=' The question is... What is generating those two lines and how can i edit that code?
To disable `comment-reply` go to `Discussion Settings` and disable `Threaded (nested) comments`. Google-hosted jQuery: function my_scripts() { wp_dequeue_script('jquery'); wp_enqueue_script( 'jquery', // name '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', // google hosted, protocol-independent array(), // dependencies (empty) NULL, // removes version true // load in footer, 'false' for header ); } add_action('wp_enqueue_scripts', 'my_scripts');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "javascript" }
Manage Inventory Without Displaying Levels I have my products set to manage inventory. Is there an option somewhere to simply make the product pages state "In Stock" rather than "X In Stock"? Or is that just set in the theme (I'm just using Twenty Twelve at the moment)?
There is actually a setting for this, found under WooCommerce, Settings, Inventory, Stock display format.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -3, "tags": "plugins" }
How to get twenty ten content side by side (images and/or text)? I try to align content side by side. I tried this solution from the Wordpress forum but it is not working for me: <
I had to guide a user through this recently, some tricks that I found: 1) Make sure the HTML is clean, that fidding in the visual editor has not added in extra paragraphs or alignments or whatever. In fact, take out all the alignleft etc. you can, get it back to a virgin state. 2) In the visual editor, select the image so it turns blue. 3) Make sure the little mountain icon is displayed on it; if not it means you've got the container selected or something like that, not the image itself 4) Click the align left icon to move the image to the left. 5) If that still doesn't work right, experiment with which image goes first in the HTML; when floating images like this it matters what the sequence is and what is inside what. At the moment in your HTML it looks like both images are aligned left, resulting in them not being side by side.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "theme twenty ten" }
Inserting post_id into guid before wp_insert_post I would like to insert data into the wp_posts table with the inserted post_id in the 'guid' for a record that doesn't already exist. Below is the closest I've gotten but this doesn't work ($postarr['ID'] is equal to 0). function filter_handler( $data , $postarr ) { if($data['post_type']=='ai1ec_event'){ $my_post_id = $postarr['ID']; $data['guid'] = get_option('siteurl') .'/?post_type=ai1ec_event&p='.$my_post_id.'&instance_id='; } return $data; } add_filter( 'wp_insert_post_data' , 'filter_handler' , '99', 2 ); $mypost = array( 'post_author' => 1, 'post_content' => 'Test', 'post_status' => 'publish', 'post_title' => $_GET['assignment_name'], 'post_type' => 'ai1ec_event', 'guid' => '' ); $postid = wp_insert_post($mypost);
Why would you need that? ID in a database is auto increment - it manages it's value itself. If your target is to set custom guid, you should update the inserted post as soon as it is created via wp_update_post right after your $post_id = wp_inserted_post($mypost); like this: ...Your code above... $postid = wp_insert_post($mypost); $data = array( 'ID' => $postid, 'guid' => get_option('siteurl') .'/?post_type=ai1ec_event&p='.$postid.'&instance_id=' ); wp_update_post( $data );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp insert post, guids" }
Can't get custom user meta to show in header I have used Pie Register plugin to add a "Phone" field. I tried every method in the book (that google fetched for me, so far) to show it but it shows an empty array although the field is not empty and the wordpress backend shows it. Also, User Meta plugin is able to show the field with its data but I can't get it to show manually in my header file. Any help is appreciated, I spent hours without any luck doing this! Thanks
Try this code: echo get_user_meta( get_current_user_id(), 'phone', true ); And pay attantion about that plugin. The plugin is not using any prefixes, so when you'll create a custom filed with same name as any WordPress user_meta, it will override this one.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, functions, themes" }
what is the difference between timthumb and post thumbnail? I get the image through wordpress built in post_thumbnail, but i see a lot of developers use timthumb for that and i don't know why! is it more flexible or something?
There are two reasons: 1. post_thumbnail was introduced with WordPress 2.9, and many themes which used TimThumb because post_thumbnail wasn't yet available to them. 2. TimThumb is more flexible than post_thumbnail — it gives you more options for how images are cropped, and allows for simple filters to be applied to the images. However, TimThumb has also caused security issues, especially with sites which didn't keep their themes (and because of this their timthumb versions) up to date. Because of this, it often makes more sense to use post-thumbnail, especially if you don't need much beyond WordPress' built-in cropping for thumbnails.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post thumbnails, timthumb" }
Conditional Custom field with foreach i use use this code to set slider in header with CF, how i can disable when CF is empty or set another CF key to exclude it? <?php $custom_fields = get_post_custom($post_id);//Current post id $my_custom_field = $custom_fields['slider_id'];//key name foreach ( $my_custom_field as $key => $value ) echo get_new_royalslider($value) ; ?>
Less code lines with `get_post_custom_values()` $values = get_post_custom_values('slider_id', $post_id); // if non-empty if($values) { foreach($values as $value) echo get_new_royalslider($value); } If `$values` array is empty, nothing happens.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "advanced custom fields" }
query posts and custom post type with meta key I'm trying to query all-in-one-event-calendar's custom post type ai1ec_event and normal wordpress posts in a slider on my home page. That works pretty well. Now I want to query only the posts with the custom field value "teaser", but that returns just normal posts, not the events. <?php query_posts( array( 'post_type'=>array('post','ai1ec_event'), 'posts_per_page' => 50, 'meta_query' => array( array( 'key' => 'teaser', 'value' => 'on' ) ) ); ?> Even if I leave out the post type query: <?php query_posts( array( 'meta_query' => array( array( 'key' => 'teaser', 'value' => 'on' ) ) ); ?> it only returns posts, no events.
I'm afraid WP_Query is not able to fetch (Posts with custom field) or (ailec_even). You'll have to query the firs one, than the second one and merge those arrays. Use WP_Query instead of query_posts. I've just tried it on my local installation and this code called from index.php of twentytwelve works (brings post with title "Hello post" and ai1ec_event with title "Event" - both with custom field "teaser" with value "on" $events_query = new WP_Query( array('post_type' => array('ai1ec_event', 'post'), 'meta_query' => array( array( 'key' => 'teaser', 'value' => 'on' ) )) ); while ( $events_query->have_posts() ) : $events_query->the_post(); echo get_the_title() . '<br/>'; endwhile; Have to say that both (post end event) were created by admin user - I've checked the code and there is an extensive part with custom capabilities.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, custom field, query, meta value" }
Showing the next post's title, even if it's an unpublished post At the bottom of each post I need to either: * Offer a link to the next post (if the next post is published); or * Display the title of the next post with the date it will be published (if it's a future post) Suggestions?
Add these two where you want them to display within your single.php file. It will make the title of the post a link. <?php previous_post_link(); ?> <?php next_post_link(); ?> EDIT: Sorry I missed the second part of your question about future posts. Here's what I would probably do. It's not tested, but will give you an idea. $adjacent_post = get_adjacent_post(false,'',false) ; if (get_post_status( $adjacent_post->ID ) == 'publish'){ echo '<?php next_post_link(); ?>'; } else { echo get_the_title($adjacent_post->ID).' | '. $adjacent_post->post_date; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "publish, next post link" }
Upload a custom csv file, read contents and delete that file Can someone please direct me to a resource or give me some pointers on: * How to upload a csv file to wordpress (media uploader or alternate methods, ajax powered preferred) * Access that file so I can read the contents I am not looking for a plugin as this is a custom file that I need to read and process inside a plugin. Ideally, this workflow is desired: **Choose a file** > **Click Upload** > **Plugin accesses the file after upload** and processes file content > **Plugin deletes the file**. Bold steps interest me the most.
1. Enable upload of CSV files, which are not in the default allowed files (see here) 2. Hook into add_attachment action hook to detect when the desired file is uploaded 3. Do whatever you need to do using that hook, then trigger wp_delete_attachment once the file has been processed. Depending on what you want to do, it may be beneficial to craft your own upload setup outside the default Media Manager where it would be easier to detect when a file uploaded should be processed by your plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "uploads" }
WordPress Translation to french, at -> à not working I have a german / french blog. I installed the german WordPress version, so I already had de_DE.mo and de_DE.po in wp-content/languages. After I realized that the content of a comment's `<time>`-element wasn't translated, I googled and downloaded fr_FR.mo and fr_FR.po and put them in wp-content/languages. Now everything I tested works, except that 'at' doesn't get translated to 'à' ( I get: 3. février 2013 at 17:00). So I opened fr_FR.po to see whether there is a translation available. I found this: #. translators: 1: date, 2: time #: wp-includes/comment-template.php:1367 msgid "%1$s at %2$s" msgstr "%1$s à %2$s" Which seems alright to me. So to make sure, I replaced the existing mo file with this. Still it does not work. How do I make it translate 'at' to 'à'? I'm using WPML.
No matter what languages your site are in, when using WPML you should **never** install a localised WordPress version, instead you should just install the default one (i.e. US English). Also make sure that you didn't change the LANG definition in your `wp-config.php` file, so that should read: `define ('WPLANG', '');` Then you need to make sure that all the strings are in English (go to WPML->String Translation, scroll down to the bottom where you can set the language of the strings). After that rescan your theme for strings and you will be able to add translations for "at" in both German and French.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multi language, localization, plugin wpml, translation" }
How do I access the media settings I have been trying to find a way to access the the maximum width of a large image as set on the media settings page? In my theme I am grabbing images from a server and have the ability to specify the size when I grab them. I want to grab the image with the width set for the large image size on the media settings page.
The sizes are stored in the options table in the database, so you can grab values with `get_option('large_size_w');` The values stored in the DB are: * thumbnail_size_w * thumbnail_size_h * medium_size_w * medium_size_h * large_size_w * large_size_h
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, theme development" }
Use WP_Query with have_posts()? Is it possible to use $items = new WP_Query( $query_args ); with <?php if(have_posts()): ?> <?php while (have_posts()) : the_post(); ?> without changing the loop to be <?php while ($items->have_posts()) : $items->the_post(); Thanks.
global $wp_query; $original_query = $wp_query; $wp_query = null; $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); the_excerpt(); endwhile; else: echo 'no posts found'; endif; $wp_query = null; $wp_query = $original_query; wp_reset_postdata(); <
stackexchange-wordpress
{ "answer_score": 11, "question_score": 5, "tags": "wp query, loop" }
Get URL Parameters from referer Not 100% sure if this one classes as a php question or is specifically Wordpress... I'm implementing the Wordpress Settings API with a tabbed settings page. I've added a 'reset tab' button, but since the validation is done on a separate page (options.php) I can't seem to figure out which tab I'm on - without adding the tab as a hidden field, which I want to avoid. I've found the `wp_get_referer()` function, but that gives me the full URL - I'm not sure how to pull the `tab=tab1` out as a variable. **Update - Answer:** $url = parse_url(wp_get_referer()); parse_str($url['query'], $path); $tab = $path['tab']; As said in the answers, some validation is then required.
If `tab=tab` is in the URL then: global $_GET; var_dump($_GET); // debugging only; You should be able to see what you need. That is pure PHP. If your really need to process that string (I don't know why your would) use `parse_url` then use `parse_str` on the `query` part of it. $path = parse_url($url); $path = parse_str($path, $output); var_dump($output); // again, just debugging For completeness, please don't use any of those values without validating them. Did I misunderstand you?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "php, urls, settings api" }
Use an archive as the parent of a page? how can I solve the following problem? I have the category "Events" with the permalink `www.myblog.com/events/` and of course single events like `www.myblog.com/events/lets-party/`. Now I want to add a custom page "Event Contacts" which should be located below "Events" like `www.myblog.com/events/contact`. But I can't choose category archives as a parent page in the backend. Any advice?
Once wordpress reads the "Events" part of the URL it knows that what follows are posts or subcategories of the events category, and a page is neither, and that is the reason you don't even have an option of doing what you want. Do it as a post instead of a page. Then edit you single.php to have special treatment for your contact post id if you need it. If you are lucky it might be enough to change the css for the specific post. Alternatively you can try to use the fact that if all other URL parsing options fail, WordPress tries to parse the URL as page, and add a page with the slug "Events" and contact as its sub page. If you go that way you need to always remember not to create sub categories or posts with the slug contact.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pages, archives, hierarchical" }
Resize uploaded images > **Possible Duplicate:** > Resizing all images I have this news portal i built, and the client want a different size of the featured image. I all ready made my first desired size and they have posted around 200+ posts all ready with that image size. Now, if i change the size it only changes on the new posts / or re upload of the current featured images(which is too much to do by hand). My Question is, is there a way to resize the uploaded images?
I use a plugin called AJAX Thumbnail Rebuild. It goes through all of the images in your media library and re-sizes them based on any image sizes registered (including the defaults and anything added with `add_image_size()`). It only runs when you manually request it and you can tell it to only rebuild certain sizes if you wish.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, post thumbnails" }
List of Registered Taxonomies of Current Post I am trying to get list of registred taxonomies of current post, I mean: register_taxonomy('color',array('thing'),$args) ; register_taxonomy('shape',array('thing'),$args) ; register_taxonomy('material',array('thing'),$args) ; // etc.. So how can I get the list of taxonomies that registred to 'thing' posttype? Must be something like: $taxonomies = get_registred_taxonomies_of('thing') ; print_r($taxonomies) // Show "color,shape,material"... Any idea? Thank you!
You are looking for **`get_object_taxonomies`** ex: $taxonomies = get_object_taxonomies('thing') ; print_r($taxonomies) // Show "color,shape,material"..
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom taxonomy" }
Function to limit the number of posts in taxonomy.php How can I change the post limit for taxonomy.php from that which is defined in the settings page? Currently I have 10 posts displaying per page, which is fine for the blog part of my site, but I want to show all posts when the user is on taxonomy.php, is there a function that can achieve this?
Use the `pre_get_posts` hook to check is you are in a taxonomy term archive and change the number of posts ex: add_action('pre_get_posts', 'change_tax_num_of_posts' ); function change_tax_num_of_posts( $wp_query ) { if( is_tax() && is_main_query()) { $wp_query->set('posts_per_page', 5); } }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom taxonomy, taxonomy" }
Using Jigoshop, how can I add a custom post type to the cart via code? I want to programmatically add an item to the cart, and that item is not a product.. It's a custom post type that I am creating. I think I'm going in the right direction by using the Jigoshop cart class. Found in the jigoshop folder under classes/jigoshop_cart.class.php. The problem is that I'm not sure exactly how to hook something into it that is not a product.. I thought maybe someone could point me the right direction. Thanks in advance!
Short answer: **You can't.** Long answer: Jigoshop is designed to only allow checkout of our "product" CPT. In reality, you should have been looking at Jigoshop's template_functions.php file which has our add to cart functions. For security reasons, Jigoshop has checks, absolutely everywhere that the CPT is in fact Jigoshop's own product CPT. Source: I'm a Core Developer at Jigoshop (it doesn't get more official than this)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "e commerce, jigoshop" }
Restrict users on multisite WordPress install I have a series of sites that I maintain as part of a WordPress multisite install. I'd like to be able to create users accounts that are restricted to viewing only a single one of these sites. Is this possible? Once this is accomplished, is there a way to determine this permission status programmatically? I'd like to be able to get a list of all the sites the current user has access to, or at the very least, test if the user has permission to access a specific site.
Use `is_user_member_of_blog()` to check if the current user has been assigned to the blog in `wp-admin/network/site-users.php`. Then hook into `template_redirect` and run the test: add_action( 'template_redirect', function() { if ( ! is_user_member_of_blog() ) die( 'Please ask the network administrator to get access to this blog.' ); });
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "multisite, user roles, permissions, user access" }
How to back-up a database on IIS I've been having trouble finding a good tutorial on how to back-up a WordPress database using IIS as the web server. I installed WordPress using IIS's web platform installer and now I can't even find where the database file resides. I've been doing everything under a local development if that helps. So my question is, how exactly do I back-up the database file associated with IIS?
I was able to find the name of the database in word-press's wp-config.php file under the and was able to create a back-up of the file using MSQL workbench and the tutorial found here <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "database, mysql, iis" }
Arrange custom fields with drag and drop? I am making theme for hotel and i made custom metabox with list of various custom fields that i would need in posts. What i did is i made a list of fields like * booking * wifienabled * coffe * pool * spa and so on... Problem is that currently i can show those custom fields in website frontend only by order how i added them in array, if i change places in my list custom fields will change places in website frontend. Is it possible that custom fields have specific order? Some kind of drag and drop to rearange those fields and change order of display in frontend?
In this example of repeatable custom fields, we can see that the following jQuery is needed: $('#repeatable-fieldset-one tbody').sortable({ opacity: 0.6, revert: true, cursor: 'move', handle: '.sort' }); And the HTML it controls is (simplified): <table id="repeatable-fieldset-one" width="100%"> <thead> <tr> <th width="2%"></th> <th width="30%">Name</th> <th width="60%">URL</th> <th width="2%"></th> </tr> </thead> <tbody> <?php if ( $repeatable_fields ) : foreach ( $repeatable_fields as $field ) { ?> <tr> <td><a class="button remove-row" href="#">-</a></td> <td>NAME FIELD</td> <td>URL FIELD</td> <td><a class="sort">|||</a></td> </tr> <?php } endif;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "custom field, jquery, metabox" }
How can i know when i can execute what functions of wordpress? I like to do a bunch of stuff only on homepage and archive pages i am working with the genesis framework (not really matters i guess) if( is_singular() ) { wp_die('functions.php'); } add_action( 'init', function() { if( is_singular() ) { wp_die('init'); } }); add_action( 'genesis_before', function() { if( is_singular() ) { wp_die('genesis_before'); } }); only the 3rd get executed, i looking for some reference about that i run into some issues like that before. How do get get to know the wordpress scructure better without digging into the source files?
Install my plugin T5 WP Load Order. You get a long detailed list with all available hooks, files, constants, classes, functions and global variables – ordered by first appearance. Whenever you’re in doubt create such a list for the page you are working on, and look up what you need.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "conditional tags, core" }
Widget logic not working I am using the Widget Logic plugin to display a widget only on certain pages. I use the condition is_page(10,16,19) to specify the pages I want the widget to display on. However, the widget does not display on these pages. I have double checked the page ID is correct, and I have cleared my browser cache, yet the widget isn't being displayed.
Refer to the `is_page()` Codex entry. You need to pass multiple Page IDs as an _array_ : is_page( array( 10,16,19 ) )
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "widgets" }
How to get postname in custom page? I'm adding custom pages in WordPress and trying to handle WordPress with my own CMS. I'm using all WordPress' hooks to manage all these things. Now, I can make a custom post saying "a new album" but I don't know how to give a post name to it. The database entry of `post_name` in the `wp_posts` table remains blank now as I don't know what to put there.
Thanks for reply to both of you. I tried to use only `sanitize_title` function but it repeats when I want to add the same name post so I did something like below in my custom commands: $post_name1 = sanitize_title($_POST['subcategory']); $post_name2 = wp_unique_post_slug($post_name1, $_POST['idofalbum'], 'publish', 'album', 0); `$post_name1` gives me title with dashes and `$post_name2` gives me unique slug which I needed.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, slug" }
Force Cron to run only on one server Given a site running on server A and server B with a load balancer, shared database/etc, and a regular wp-cron task, how would I make sure that wp-cron only runs on server A, never on server B?
I'm currently testing this in wp-config.php: if ( php_uname('n') == 'wp4' ) { define('DISABLE_WP_CRON', true); } Where wp4 is the name of the second server in the setup
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "server, cron" }
Dashboard blocker on network multisite for specific user roles I have used this function below for a while now on normal WordPress installs. It simply blocks users with specific user roles, and redirects them to the home page of the site. function wpse23007_redirect(){ if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('media') ) ){ wp_redirect(home_url()); exit; } } add_action('init','wpse23007_redirect'); But when I install this on a sub theme in my WordPress Multisite, even though I am a superuser, it is blocking me from the dashboard of my sub theme. Can anyone help me understand why this is and how to change the above so it doesn't block me?
All your role checks are relative to the user roles in the sub site in which I assume you are not a user. You should also check for `is_super_admin()` if( !is_super_admin() && (is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('media') ) ) ){ wp_redirect(home_url()); exit; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, multisite" }
Define Folder to save Images The Plugin save the Images to /PLUGINNAME/images but i want that it moves to /uploads The Code inside the Plugin is this here define('WPR_URLPATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' ); $wpr_saveurl = WPR_URLPATH . "images"; $wpr_cache = ABSPATH . "wp-content/plugins/". plugin_basename( dirname(__FILE__) )."/images"; How can I define to save the Images there?
What is "the plugin"? Anyhow , you need to change `WP_PLUGIN_URL` to `wp_upload_dir` in your `define`. You can read more here: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images" }
Wordpress Resize Image and show as thumb in post I have set crop in functions.php to resize Images for Posts. Codex from Wordpress: add_image_size, post_thumbnail add_theme_support('post-thumbnails'); set_post_thumbnail_size(100, 100, true); //size of thumbs add_image_size( 'post-thumb', 180, 180, true ); //(cropped) Usage is like below <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'post-thumb' ); } ?> But it will not resize the thumb and shows the original size. What am I doing wrong?
After adding new image sizes, you might need to rebuild your thumbnails. I have used AJAX Thumbnail Rebuild after encountering a similar issue, and it worked fine.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images" }
How to check with is_page if 404.php is loaded? I want to check if current page match at least one of two conditions. I don't want to show js code into about page and into 404 page. For the rest of my pages i show the js code. So, I use `((!is_page(element1) AND !is_page(element2))` then show the js code. Element1 is a slug of one specific page and element2 is 404.php page. I don't know the slug or name of 404 page to indicate in if statement.
I think this would do : if ( is_page( 'element1.php' ) || is_404() ) { // do that if page is using template page element1.php or is 404 }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "conditional tags" }
How can i display wath i am searching in a theme How can i display wath i am searching in a Search Theme. Ex: I search for Keword : Battleship Result : Your results retrive (3 posts) with the subject Battleship.
Add the following code to your template's search.php - somewhere before the loop: <?php global $wp_query; echo 'Your results retrive ('.$wp_query->found_posts.' posts) with the subject '.get_search_query().'.'; ?> If search.php does not exists in your template's directory, either copy archive.php (if it does not exists too, copy index.php - see template hierarchy) and rename it to search.php or insert following code, again before the loop, right into archive.php or index.php respectively: <?php if ( is_search() ){ global $wp_query; echo 'Your results retrive ('.$wp_query->found_posts.' posts) with the subject '.get_search_query().'.'; } ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": -2, "tags": "themes, search" }
Create custom welcome email without a plugin Is there a way to customize the email content and subject for the welcome and verification emails sent during the registration process for Wordpress? I'd like to hook or filter in without using a plugin or the "pluggable" feature. If someone could point me in the right direction, I'd be very appreciative. Thanks!
So I think the answer is no, you aren't able to do this in a safe manner.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 4, "tags": "email, html email" }
PHP unit testing WordPress? Given how WordPress is written and how it interacts with a database and given how its not very much OOP oriented, is there a way to unit test a theme? is there a way unit test a framework (not a theme framework) that interacts with WordPress, that is, for example, can you write a unit test for dealing with the loop, dealing with the widgets? If so does any one have any examples? I know how to write unit tests, but I have never tried to write one for a theme. Thoughts?
There is nothing stopping you from writing your own unit testing for themes/plugins using PHPUnit or some other testing platform. As for WordPress, it has an official Unit Tests here: * < * < (github mirror) There are several build scripts that can automate unit testing found here, including WP-CLI that have built in unit testing, though you have to obviously write your own code. I also found this plugin today via scibu's twitter rant :) < There are a few more in the repo: < **Also check out this** : Tutorials for Unit-Testing in WordPress and for unit-test.svn.wordpress.org?
stackexchange-wordpress
{ "answer_score": 6, "question_score": 7, "tags": "php, theme development, testing" }
How to Add Rewrite Ruled Argument Into Permalink Properly I am using WP rewrite rules for my custem arguments, But when I am trying to generate permalink like this: add_query_arg(array( 'type' => 'foo', 'paged' => 2, ),get_permalink($id)) ; It returns still: mysite.com/products/?type=foo&paged=2 But I need to turn it into this: mysite.com/products/foo/2 Rewrite rules work perfectly, but "add_query_arg".. How to solve?
I'm affraid this "nasty" solution would be the most effective than trying to write some cool function that will translate your permalinks into pretty permalinks: $permalink = rtrim( get_permalink( $id ), '/' ) . '/foo' . '/2'; The rtrim part (removing trailing slash) is just for to be sure there are not going to be two slashes on the end of the first part of your new pretty permalink.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "rewrite rules" }
WordPress mysqli and PDO Does WordPress code base use mysqli or PDO? I know PDO is superior to mysqli but mysqli is not bad neither. Plus from one of the features of what makes PDO is superior to mysqli ( that is being database agnostic ) does not mean much to WordPress as WordPress will always use mysql server. But binding params with data types is something PDO supports but mysqli does not and it's a good thing. My guts tell me that WordPress does use mysqli but I could not see it in the code base yet. My second question is if WordPress is using mysqli, is it because of speed concerns or is it because back in the earlier days (when WP was being developed), PDO wasn't just there yet?
WordPress uses `mysql_*` functions. < It has used those ever since I can remember, which probably answers your last question. It is what I would consider legacy code. I suspect it will be updated sometime soon (those functions were only deprecated as of PHP 5.5, I believe). I don't know which route development will go. Link to a ticket in Trac, courtesy of Wyck (from a comment below): <
stackexchange-wordpress
{ "answer_score": 7, "question_score": 13, "tags": "mysql" }
The content not wrapped in paragraph tags with get_page_by_title() I am using `$page = get_page_by_title('name')`; to get the contents of a page. When I echo `$page->post_content;` none of the content is wrapped in p tags like it is when run threw the normal wordpress loop using `the_content(`). Is there a different way I should get this data so it will contain the proper tags?
You can apply the content filters to `$page->post_content` like so: echo apply_filters('the_content', $page->post_content);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, pages, theme options" }
Pagination 404 errors for author posts query on author.php I'm trying to query all posts by an author and paginate them on the author.php page. I've tried messing with the WP default blogs per page settings and that doesn't help. I've looked at other posts on here and could find a solution either. This works on my category pages and custom template pages (with the exception of the author attribute). Here's what I have for my query: if (get_the_author_meta( 'ID' )) { $authorID = get_the_author_meta( 'ID' ); } $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'post', 'author'=>$authorID, 'orderby'=> 'date', 'showposts'=>'5', 'paged'=>$paged ); $query = new WP_Query( $args ); I even tried query_posts() with no luck. The query itself works, but the pagination breaks. Any ideas?
There is already a query on that page. `author.php` is an optional template file that, if present, WordPress will use for author archives. You shouldn't have to create another query on that page. I think that your query and the native query are colliding, at least in part because both queries will be using the same `paged` query var. If you need to change something about the query, you should probably be interrupting the main query for that page instead of creating a new query. function alter_author_wpse_84696() { if (!is_author()) return false; global $wp_query; $wp_query->set('posts_per_page', 10); $wp_query->set('order', 'ASC'); } add_action('pre_get_posts','alter_author_wpse_84696');
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "wp query, pagination, author" }
Where is this strange og:description coming from? I noticed in my home page's source code: <meta property="og:description" content="This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say s" /> This is a problem since this is what Facebook uses when I post the main URL of my site to a Facebook wall... so it just looks stupid. I can't find that string anywhere in my WP admin settings, or in the "Facebook Open Graph Options" setting (as part of the "Facebook OpenGraph" plugin that I have installed). It's also not in any of my theme's template files, and it's not on my actual about page. Where can I find this description, so I can change it?! Thank you-- E
That's a FaceBook plugin most likely using the output of the `post excerpt` \- via `get_the_excerpt()` or whatever - to populate the `og:description` meta tag. It's placed there automatically by the plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, facebook" }
Wordpress Mobile Edition not working with WP v3.5 Since upgrading Wordpress from 3.4.2 to 3.5, Wordpress Mobile Edition has not worked. I have left a support request on the plugin's support page, but have received no reply in 2 weeks. I might have to conclude the plugin author is no longer supporting this plugin. I know this question might breach guidelines, but is there a ready alternative to using Wordpress Mobile Edition? Perhaps this doesn't have to be a plugin, but might be a Wordpress hack. I have a customised version of Carrington Mobile I'd like to retain.
The plugin you are using hasn't been updated in 2 years. Check out the Jetpack for WordPress plugin. It comes with MANY useful modules, one of which is the **Mobile Theme** module. Another plugin that comes to mind is WPtouch, which is available in basic and pro ($$) builds.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "mobile" }
Is there any way to use get_template_part() with folders? I'm wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I'd like to put them in folders then. There is no information about that in Codex: <
In fact you can, I have a folder in my theme directory called `/partials/` in in that folder I have files such as `latest-articles.php`, `latest-news.php` and `latest-statements.php` and I load these files using `get_template_part()` like: get_template_part('partials/latest', 'news'); get_template_part('partials/latest', 'articles'); get_template_part('partials/latest', 'statements'); Just dont forget to omit the `.php` from the file name.
stackexchange-wordpress
{ "answer_score": 51, "question_score": 32, "tags": "templates, include, get template part, template include" }
Wordpress Gallery not being output correctly/consistently Using WP 3.5.0, Wordpress galleries have been working fine. I use the Cleaner Gallery plugin and Lightbox to display galleries in lightbox mode. Now I am using WP 3.5.1, a gallery I created on this page is output with inconsistant hyperlinks on the thumbnails. Some point to a URL with format: < Some point to a URL with format: < Both fail to load larger images in the lightbox, producing message "image cannot be loaded, please check the image filename and path and try again". To me, the hyperlinks on the thumbnails are not correct, but I can't see why Wordpress would be producing this.
It looks like you have the gallery settings pointing to the attachment pages instead of the media files directly. You can try this shortcode [gallery size="full" link="file"] instead of the default [gallery] if you want different sizes, you can change the **size** parameter to size="thumb", size="medium", size="large" or to the image-size-name you want to use.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "gallery" }
Reusing the page name class that Wordpress adds to body tag When viewing my blog in the browser, the body tag (on the index page) has the following class: <body class="home"> On other pages (for this example, a page that pulls in posts that are within the category "project"), the body tag has even more classes: <body class="archive category category-project category-3"> Both of these are rendered using the following code, contained within the html_header part: <body <?php body_class(); ?>> I was wondering whether there was a way in which I could isolate the page descriptive class (1st example - home, 2nd example - category-project) that this command targets and use within the page. Thanks
The Function `get_body_class()` gives you an `Array` containing all the classes that are added to the body, so you can reuse them.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php" }
How to edit wp-signup.php content using plugin I need your help as I got some issue with `wp-signup.php` page which I try to resolve but I am not able to do it. Issue is as follows, 1. I want to replace the text 'Get your own %s account in seconds' with 'Fields with an asterisk will be shown on your website for the world to see'. I know that i can do it by going to the `wp-signup.php` page and hardcode the text in `signup_user()` but i want it to be handle with the help of a plugin so that even if wordpress upgrade then this will not affect the text. 2. I want to remove radio button with label (Just a username, please.) from the `signup_user()` Any help will be appriciated, I am waiting for you reply.
you can try these hooks: // // remove label label[for=signupuser] and #signupuser on wp-signup.php with CSS // add_action('signup_header','my_signup'); function my_signup() { echo "<style>label[for=signupuser],#signupuser{display:none !important;}</style>"; } // // edit text displayed on wp-signup.php // add_filter( 'gettext', 'my_change_text', 20 ,3); function my_change_text( $translated_text, $text, $domain ) { if ( $domain =="your_site_name") { // EDIT if( trim($translated_text)=="Get your own %s account in seconds"){ $translated_text="Fields with an asterisk will be shown on your website for the world to see"; } } return $translated_text; } where you will have to edit the value **$domain =="your_site_name"**. This will give you the following result (see the attached image): !wp-signup modifications via hooks
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, multisite" }
Get first category only and excluding one How can I get the first category (linked to the category archive page) of a post excluding the category called 'featured'? I found various solutions but I can't combine them properly. Thanks UPDATE: This is what I ended up using: $category = get_the_category(); $cat_id = get_cat_ID( $name ); $link = get_category_link( $cat_id ); if($category[0]->cat_name == "featured") { echo '<a href="'. esc_url( $link ) .'"">'. $category[1]->cat_name .'</a>'; } else { echo '<a href="'. esc_url( $link ) .'"">'. $category[0]->cat_name .'</a>'; }
Within the post loop you can do, $category = get_the_category(); if($category[0]->cat_name == "featured") { //if first category in array is "featured", get next category in line $name = $category[1]->cat_name; $cat_id = get_cat_ID( $name ); $link = get_category_link( $cat_id ); echo '<a href="'. esc_url( $link ) .'"">'. $name .'</a>'; } else { //get the first category $name = $category[0]->cat_name; $cat_id = get_cat_ID( $name ); $link = get_category_link( $cat_id ); echo '<a href="'. esc_url( $link ) .'"">'. $name .'</a>'; } If you are outside the loop you can pass a post ID to `get_the_category($id);` Note: Its crude... you could simplify this logic. Edit: Here is a link to an answer that provides a more refined approach using the `array_pop` which you could adapt to your situation: Get the first post term
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "exclude, categories" }
Custom Meta Box If Else Statement I have created a custom meta box for posts and I need to display said data. I have been using the below method to display the data, But I am in need of a slightly different solution. <a href="<?php echo esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text4', true ) ); ?>"> <img src="<?php echo esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text3', true ) ); ?>" alt="" onerror="this.style.display='none'"/> </a> What I need is a way to do a IF/Else statement such is. If `my_meta_box_text3` exists `echo that`, else `echo this`.
You can try this: <?php // get image source: $metaboxtext3 = esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text3', true ) ); // get link: $metaboxtext4 = esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text4', true ) ); // check if the image source exists: if(strlen($metaboxtext3)>0){ ?> <a href="<?php echo $metaboxtext4; ?>"><img src="<?php echo $metaboxtext3; ?>" alt="" onerror="this.style.display='none'"/></a> <?php } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, loop, metabox, conditional content" }
Is the 404 page automatically displayed if a loop returns nothing? If you have an `index.php` with a loop such as: if(have_posts()){ while(have_posts()){ the_post(); } } And nothing is returned, you would generally do a: if(have_posts()){ while(have_posts()){ the_post(); } }else{ //display message } However, what if you have a `404.php`? Will that page be displayed if nothing is returned in terms of the loop (assuming I have not written the else part of the loop)?
If you want to force the `404.php` template to load if there are no found posts, use the `template_include` filter: function wpa84794_template_check( $template ) { global $wp_query; if ( 0 == $wp_query->found_posts ){ $template = locate_template( array( '404.php', $template ), false ); } return $template; } add_filter( 'template_include', 'wpa84794_template_check' );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, loop, 404 error" }
Custom post types problem I have in my blog around 2k+ posts in 15 categories and around 1k tags. The problem now is that the website I bought the theme from decided to upgrade/update their themes infrastructure and now I need to export my normal posts into a custom post type. Ill explain below. To be able to use their portofolio grid template they have created a custom post type called portofolio and all posts created with that custom post type will be displayed in a portofolio grid style. Before the upgrade this was different, once you added a post category you could select the template you wanted to use for that category, but now they decided to create custom post type called "portofolio" and all posts in there will be displayed in the grid portofolio template. They turned around and said to me that i must start from square one since there is no way to export normal posts into the new custom post type. So what are my chances guys? The theme is called videogrid by themefuse
I'd recommend pTypeConverter instead of Post Type Switcher. I've run into a couple of odd issues when using it. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, themes, theme options" }
Simple fields plugin WordPress show repeatable file field I have install the plugin Simple fields for WordPress, create an repeatable field for file. Upload an amount of images to an portfolio item. Now I will show these images on the page. I use currently the following code: $file_id = simple_fields_value('image_repeater'); $image_info = wp_get_attachment_image_src($file_id, "full"); $image_url = $image_info[0]; echo "<img src='$image_url' class='imagebox' />"; This will show only the first image that I have uploaded. Now I want to show also the other images, but I don't know how. Hope somebody can help me out! Thank you!
For repeatable fields you can use the function simple_fields_values to get an array with all the field values. You can then loop through the array and do whatever you want with the values (in this case the images). See more info here: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Reordering content using a meta value I've got this theme where you can add posts of type "portfolio", and I want to be able to reorder them up. I've added a custom meta field called "position" and I've set already those values. All good. My question is: How can I modify the query to join the wp_postmeta table and order them by the "postion" value? This is the current query: $loop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => $homepagenumber ) ); I really appreciate any hint on this. Thanks a lot.
Check WP_Query Order by Parameters $args = array( 'post_type' => 'my_custom_post_type', 'meta_key' => 'age', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'age', 'value' => array(3, 4), 'compare' => 'IN', ) ) ); $query = new WP_Query($args);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, join tables" }
How to add subscript and superscript in WordPress page titles It is possible to add subscript and superscript in a WordPress page title? I need to add pages with "H2O" in the title. I have been searching, but cannot find anything with answers... only a few non-answered threads on wordpress.org forums.
You can use markup in titles. `H<sub>2</sub>O` will work just fine. I would use H₂O with a real `₂` because markup will be stripped in title attributes and in feeds. Note that WordPress will not create a pretty permalink for the correct character. The slug for my example will look like this: `h2o-h%e2%82%82o`. You need my plugin Germanix URL to get `h2o` for both variants. !enter image description here
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "title" }
order of date column in custom post type I have a custom post type and trying to set custom columns, the date column is there by default, and it appears right after the title. Do I have to unset the date first and then re-apply it, or is there a more elegant way of achieving this: function custom_columns($columns) { unset( $columns['date'] ); $columns = array_merge($columns, array( 'title' => 'Alert Title', 'region' => 'Region', 'date' => 'Date', ) ); return $columns; }
That's the only thing there is to do: _array manipulation_. The filter `manage_edit-CPT_columns` is fired in **`class-wp-list-table.php`**: add_filter( "manage_{$this->screen->id}_columns", array( &$this, 'get_columns' ), 0 ); Which in turn dispatches the function `get_columns()` in the sub-class **`class-wp-posts-list-table.php`**. And, inside it, one filter for taxonomies, and others for _post/page/cpt_ columns. And all of them dealing with array elements. Maybe a _one line solution_ exists with some PHP function, but two lines is valid code too.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "custom post types, columns" }
Updating parent themes vs. updating starter theme # Context: I use framework parent themes (e.g. Thematic) mainly because it ensures that my custom themes inherit cutting-edge and standard compliant code. # Why I'm not yet using starter themes: I'm reluctant to use starter themes (e.g. _s, Bones etc.) because, as I understand it, I'll need to screen for code changes with every version update and then manually apply them to my custom theme. I'd rather # My question: Is my understanding of the process of updating starter themes correct and if so, is it not less work to simply **reverse engineer a parent theme once and have automated version** updates rather than **repeatedly manually (and perhaps tediously) having to update my custom starter theme**?
You can enable child themes for any theme: < If you want your parent theme based off another parent theme, for example you want a theme based off of _Twitter bootstrap_ and apply any changes they make to your framework, without over-riding your changes, use revision control. Git Mercurial etc.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "framework, parent theme" }
WP_UnitTestCase missing? I was looking at tests for wordpress and some, if not all the classes have WP_UnitTestCase but I cannot find the class, why do I care? I have downloaded The most up to date version of this from github which is the same set of tests. Why does this matter so much? Because when ever I run one of the tests via phpunit filename.php I get the error from php unit stating that its missing WP_UnitTestCase. So my question is: Where is this class, why is it missing if it works for the WordPress developers?
This class is defined in `includes/testcase.php`. If you checkout the entire repo, you should have it. To check out the entire repo, you should be running something along the lines of: svn co wordpress-tests
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "testing, unit tests" }
How to insert category list into post creation page, and retrieve chosen categories? I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page. !where I would like to display it I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
By default page post type doesn't support category taxonomy. But you can easily fix it by register category taxonomy for page post type: add_action( 'init', 'wpse8170_init' ); function wpse8170_init() { register_taxonomy_for_object_type( 'category', 'page' ); } Now you will see categories meta box in the same place as you see it at post creation page. To get page's categories just call `wp_get_post_categories` function like this (thanks to @Subharanjan): $page_categories = wp_get_post_categories( get_the_ID() );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, loop, pages, templates, dashboard" }
How to Detect That WP is Using Mod Rewrite or $_GET variables? I am trying to get WP is using Mod_Write or $_GET for URLs, Because by it, I can generate my own links like: mysite.com/val1/val2 or in a conventional way; mysite.com/?var1=val1&var2=val2 $_GET or rewrite, how to detect that which way WP is currently using?
You can check for the `permalink_structure` option value. If this value is an empty string, WP is using the default permalink structure (`/?var1=val1&var2=val2`), otherwise WP will be using the pretty permalink structure (`/val1/val2`): if ('' != get_option('permalink_structure')) { // pretty permalink '/val1/val2' ... } else { // default permalink '/?var1=val1&var2=val2' ... }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "url rewriting" }
Title image is missing ( but is not the WP 3.5 issue ) I use Wp 3.4.2 and Featured Image. After I feel the Title, Alternate Text and publish the post, html code looks like this: <img width="214" height="300" title="" alt="Test" class="frame wp-post-image" src=" Is there a way to fix this?
you can try this filter add_filter('wp_get_attachment_image_attributes', 'my_img_title', 10, 2); function my_img_title($attr, $attachment = null){ $attr['title'] = get_post($attachment->ID)->post_title; return $attr; } It should give the the extra title attribute in the img tag. You can also use the 'post_thumbnail_html' filter to edit the html output. ps: here is a similar question: Display info from custom fields in all images' HTML
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, post thumbnails, featured post, wp title" }
how can authors to define custom pages? I have a options page and i use this code. I want this, I add author id on sometext field (e.g 3,2,5,11 ) and my author.php redirect custom author page. My author.php <?php $post = $wp_query->post; $options = get_option('sample_theme_options'); if (is_author( array($options['sometext']) ) ) { include(TEMPLATEPATH . '/brand.php'); } else { include (TEMPLATEPATH . '/customauthor.php'); } ?> Im adding Some Text field number like this 3,2,5,11 <?php echo $options['sometext']; ?> And code Output: 3,2,5,11 But my author.php not working good. Just first id working other id not working. How can i fix it?
You can do the following: <?php $post = $wp_query->post; $options = get_option( 'sample_theme_options' ); $authors = explode( ',', $options['sometext'] ); if ( is_author( $authors ) ) { include ( TEMPLATEPATH . '/brand.php' ); } else { include ( TEMPLATEPATH . '/customauthor.php' ); } ?> This way, you're _always_ sure that `$authors` contains an array.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, posts, functions, author" }
Allow editors to post iframes I just found out that editors are not allowed to post iframes (e.g. YouTube videos). Is it possible to allow it somehow? I use WP Multisite.
try the iframe shortcode plugin < > Embed iframe using shortcode [iframe src=" width="100%" height="480"] ps: you can also use the default oembed shortcode: [embed width="123" height="456"]...[/embed] it supports YouTube, Vimeo, DailyMotion, Flickr, Twitter, ... and more. Example: [embed width="600" height="456"] Screenshot: ![]( See more here: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "user roles, iframe" }
wordpress widgets screen disappeared Im having a weird problem. The screen where you manage widgets (drag and drop them from left to right) suddenly disappeared. How can I access it? It should be accessible via admin>themes>widgets but I dont have that option in the sub menu. Only have "themes" "menus" "editor" Btw, Im using ithemes theme builder plugin. Since I have access to the editor and can edit php I assume I have admin rights.
This is both a change in WordPress core in 3.5, and a problem specific to your commercial Theme. In WordPress 3.5, if a Theme does not register support for dynamic sidebars (i.e. Widgets), then the WP-Admin does not display the `Appearance -> Widgets` admin page. So, if the behavior changed between WordPress 3.4 and 3.5, or if the screen re-appears if you switch to Twenty Twelve/Eleven/Ten, then the problem is that your chosen Theme doesn't support Widgets. Specific to your commercial Theme, iThemes builder, this is a known bug, and one that was apparently fixed. If you need any additional assistance with this commercial Theme, you should contact the developer, iThemes.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "widgets" }
exclude a post from wp_query loop 0 down vote favorite I show my last post in a page with this code: $query1 = new WP_Query(); $query1->the_post(); and it further with: $id = $query->ID; to retrieve last post ID so I wrote a new wp_query and I want to exclue that ID from the results: I wrote this but it don't work: $query2-> new WP_Query('p=-$id'); what's the problem?
If I'm understanding your specific question (and posted code) correctly, you're actually trying to exclude the **most recent** post from your query? If so, there's a _much_ easier method: use the `offset` parameter: $query2 = new WP_Query( array( 'offset' => 1 ) ); Using this method, you exclude the most recent post from `$query2`, and never actually need to run `$query1`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
Get current menu_order WordPress implements a simple order functionality by default. What's the common method, to retrieve the `menu_order` for the current post or page?
If you have the post with an `$id`: $thispost = get_post($id); $menu_order = $thispost->menu_order; WordPress itself does not provide a function to get the `menu_order`, so you have to query the `post`-Object. If you are outside the loop, you can use the above function, however inside the loop you could also achieve this by: global $post; $menu_order = $post->menu_order; The Menuorder is mainly used for Database Queries, as the Name says, do determine the Order of the output (if the menuorder is selected to be the order criteria).
stackexchange-wordpress
{ "answer_score": 17, "question_score": 9, "tags": "posts, pages, order, menu order" }
Limit user to one comment is there a nice function I can use to limit logged in users to one comment per post? I'm setting up a review system and only one review permitted per user. Thanks.
<?php global $current_user; $args = array( 'user_id' => $current_user->ID, 'post_id' = 100, // post ID. Can be '$post->ID' depending where you are calling this from 'count' => true ); if(get_comments($args) >= 1){ echo 'disabled'; } else { comment_form(); } Function_Reference/get_comments Based on AndrettiMilas code.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "comments" }
Turning a WP Site Into an iPhone/iPad App With the advent of responsive design, it's beginning to simply make sense that we could make a site into an app. The concept is simple: * When the user is on the site, remove the browser around the site so that it appears to be like any other app * Provide the appropriately-sized icons for devices (tablets, smartphones, etc.) * Meet all criteria necessary to distribute the app via the Apple app store I'm curious if anybody has the hacks, tutorial, or information necessary to achieve this.
The best way to do this would be to use CSS3 media quires: `@media (max-device-width: 480px)` but requires more work. The quick and dirty way to make your WordPress theme app-like would be to add the viewport meta tag to the `<head>` of your page: `<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> ` Viewport scales you page to fit the users device. To hide the address bar in iOS and Android Just add this line of JavaScript to your page: // When ready... window.addEventListener("load",function() { // Set a timeout... setTimeout(function(){ // Hide the address bar! window.scrollTo(0, 1); }, 0); }); You can also add this meta tag witch tells iOS your site is a web app and to hide the address bar: `<meta name="apple-mobile-web-app-capable" content="yes" />`
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "hacks, responsive, iphone" }
How to add additional JavaScript code I'm developing a mobile site and the template I'm using is based off of Jquery Mobile. In the header.php file, the template I am using is making calls to CDN javascript files: <link rel="stylesheet" href=" 1.2.0.min.css" /> <script src=" <script src=" Since I'm basically pulling in the JavaScript from those URLS and it's not actually some .js file in a folder on my web server - how would I go about adding additional javascript code? Do I add it to my header.php? Get a special plugin that'll allow me to add additional javascript? The template doesn't give my any option to add additional code. So, not sure where the code would actually go... Thanks in advance
Technically yes, you can add those lines to your header.php file just after the wp_head() function and it'll load the jQuery from a remote source, just like it was on your local machine. If you want to do it properly, take a look at < which will allow you to add it through the wp_head() hook, which will check to make sure the script hasn't already been loaded.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "javascript" }
WordPress Gallery Permalink Structure Displaying Incorrectly When an image is added to a gallery, the resulting attachment URL is generally displayed in a structure like this: **example.com/post-slug/attachment-slug/** However, take a look at my gallery: < and view an image. What could be preventing this slug from appearing correctly? The images have been attached to the post properly.
you have to edit your settings > permalinks
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "attachments, gallery" }
How to recognise on which site the content is being rendered? I've created a child theme basing on twenty twelve. Since I present the content a little bit different on home and on the archive page, I'd like to know inside `content-[format].php` on which page the post is being rendered. Then, I can decide which image size I can present. How can I know it?
You can use the global `$template`. The following function returns the `basename` of the template file being used: `index`, `archive`, etc. function get_template_name_wpse_85011() { global $template; $filename = basename( $template, '.php' ); return $filename; } And use it in your template with something like: $templat = get_template_name_wpse_85011(); switch( $templat ) { case 'index': // do index break; case 'archive': // do archive break; default: break; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post formats, images" }
Adding wp_list_categories to a specific div that was appended using jQuery Due to the way my projects menu is coded/styled I'm having some difficulty figuring this out. I have appended a div to my menu using jQuery, and I want to be able to include an external php file that simply contains a wp_list_categories(); function wrapped in an unordered list. What would be the best way to go about doing this so that wordpress recognises the wp_list_categories functions and works as I've intended? or is there a better/easier solution.
Use `wp_localize_script` to pass PHP data to Javascript. Store the result in a variable by setting the `echo` parameter of `wp_list_categories()` to `false`, and then pass the variable in the object you send to javascript through `wp_localize_script`. On a side note, I am not sure why you are having this problem at all, honestly: can you not hide your dropdowns with CSS? Or even `detach` them with jQuery on `jQuery(document).ready()`, to reapply them when you need them?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, jquery, categories" }
jQuery.accordion isn't a function even when enqueued I'm trying to implement a jQuery accordion for a client of ours. Basically, it's this tutorial (< but having problems enqueuing the jQuery. Basically, this is the code that is trying to enqueue the accordion script from the tutorial:- add_action( 'wp_enqueue_scripts', 'fl_enqueue' ); function fl_enqueue() { wp_register_style('fl-jquery-ui-style', ' wp_enqueue_style('fl-jquery-ui-style'); wp_register_script('fl-custom-js', get_template_directory_uri() . '/faq/faq.js', 'jquery-ui-accordion', '', true); wp_enqueue_script('fl-custom-js'); } When loading the page with Firebug, I'm getting the error TypeError: jQuery(...).accordion is not a function. I also cannot seem to see the accordion script being enqueued. However, the faq.js IS being loaded (which I think is odd, as it's a dependancy of the accordion script). Baffled by this, any ideas?
The 3rd parameter in the call to `wp_register_script()` should be an array of dependencies - not a string. Change this: `wp_register_script('fl-custom-js', get_template_directory_uri() . '/faq/faq.js', 'jquery-ui-accordion', '', true);` To: `wp_register_script('fl-custom-js', get_template_directory_uri() . '/faq/faq.js', array('jquery-ui-accordion'), '', true);`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "jquery, jquery ui" }
Retrieve default permalink while using seo friendly URLs in WordPress I have a client site that uses seo friendly URL's (/postname/) Up until yesterday they were using the default permalink structure of ?p=1234 They've had it set like that for years and have had their posts shared on facebook, twitter, and other networks. The problem with changing the permalinks now is that the social media sharing badges on their site have all reset their counts to 0 because the actual URL has changed. I read that Twitter would eventually begin updating itself due to it's use of checking redirected URL's but that is not the case for facebook. I would like to edit the code for the sharing buttons to pull in the original permalink instead of the new one. Is that possible? ie. $plink = get_permalink($post->ID); $eplink = urlencode($plink); What can I use in it's place to pull in the original p=1234 instead of the seo friendly name? Thanks.
Use one of the_shortlink (complete link) or wp_get_shortlink() (bare link) both introduced in WordPress 3.0.0.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "permalinks" }
Why is WordPress saving full-urls to the database? Every time im about to put my local project into staging/production environment im beeing hardly reminded that WordPress saves all the urls as absolute.So i need to rewrite all the urls with a SQL-query, or use something like Search-and-replace script. **But why is WordPress doing this?** What is the benefits? Is it a must for WordPress to work correctly? There are themes like Roots where there are functions like `roots_root_relative_url` using `preg_replace` to remove the full url. Wouldn't it be better to only have relative urls, **what is the downsides of that?** **The benefits of Relative urls in the database can be:** Easy migration from local to stage/production on all links, attachments and so on. Cleaner, shorter urls in html. But, Because WordPress doing absolute urls i sure that its good, im only want to now why and why not.
If there were only relative URLs, what would they be relative to? A post can be viewed in several different contexts, including a feed, and a WordPress install can move into a different directory relative to root. There are issues with doing it either way, absolute URLs just give you a more concrete starting point from which to make changes.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "urls" }
Allow public to post on blog I need public users to be able to submit posts, then have them be approved by a moderator or admin on the dashboard. Is this possible to do? I would like it to function very similarly to comments. for example, users will post their own stories and then a moderator will approve it being posted. I am new to this particular stackexchange (I use stackoverflow often) and wordpress development, so forgive me if this seems like a stupid question.
If you don't want to give users access to the WordPress admin screens and you don't want to use a premium plugin, you should create a form in a page and use wp_insert_post with the submitted data. In your case, the "post_status" parameter could be used to "moderate": $post = array( 'post_title' => $_POST['title_field'], 'post_content' => $_POST['content_field'], 'post_status' => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ] //Set the status of the new post. ); wp_insert_post($post); The **wp_insert_post** function should take care of sanitizing the data before inserting it into the DB, but I recommend to double check and add filters if necessary.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, users" }
subdirectory install breaking existing links I've had this issue several times now. While building a site, including some content, I keep WordPress in a subdirectory (say, `/wordpress/`). When putting it live, I move/copy 3 files out of the dir into the root, in accordance with the WordPress specifications here: < It works, but all the links already entered in content refer to `/wordpress/bla/bla` and will, after the move, return 'file not found'. Also, links previously sent in emails and links already indexed by Google will return file not found. My question: Is this behaviour as designed, or am I doing something wrong? Please note: My question is not how to fix it. It's easy enough to add some lines to the root `.htaccess` to say, "for every request inside `/wordpress/`, if it doesn't exist, remove the word `/wordpress/` and try again," so I'm surprised WordPress doesn't do that by itself. This makes me think I'm doing something wrong.
You're not doing anything wrong. WordPress does not monitor the links within content, so it's up to you to change them when your structure changes.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "url rewriting, htaccess, installation, directory" }
Separate Out Real Users If I look at /wp-admin/users.php I see all the users, but some have given a bogus email and never used their password. Is there some way to see who has used their password at least once? If not, is there a plugin to do this going forward?
## If you install the following plugin and leave that one running for a while... you can see who logged in since using that plugin: < !enter image description here That seems to do what you need. As far as I quickly can see it runs on $this->hook( 'wp_login' ) and does: $user = get_user_by( 'login', $user_login ); update_user_meta( $user->ID, 'last-login-in-meta-table', time() ); Possibly the user-settings-time in the meta table can help somewhat on determining the history before installing the plugin, never used it (see <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "users, security" }
”doing_wp_cron” in URL even if ALTERNATE CRON is not in wp-config The insertion of `?doing_wp_cron` in Wordpress’s URL is very well documented here. My problem is a little different. I turned on the `ALTERNATE_WP_CRON` feature in my `wp-config` file a few days ago. Then, noticing this issue –i.e. the introduction of `?doing_wp_cron` in my URLs– I disabled it. And by “disabled” I mean I completely removed it from the `wp-config` file. I did this 36 hours ago. My problem is that `?doing_wp_cron` is still showing up in my access log. I wonder why? My two hypothesis are: 1) I should not remove `ALTERNATE_WP_CRON` but instead I should give it the value `FALSE` 2) Those URLs are in some browsers cache and being served as such. With time they should disappear. Feedback will be appreciated. P.
I have confirmed with my host that this is a normal occurrence in access logs when running WordPress crons. Also, since I disabled `ALTERNATE_WP_CRON` I didn’t come across any actual (live) URLs with the `?doing_wp_cron` attached to them.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "cron" }
prevent custom widget file names from showing in Appearance > Editor I've setup a few custom widgets for my theme, and when I go into Appearance > Editor, the widget file names are showing up in the list of files that can be edited. How can I prevent these widget file names from showing up in the Editor's list of files? I put them in a subdirectory ("widgets"), but they are still showing up on the list with the main pages.
The editor won't traverse more than one directory deep, so a simple way to hide them is to put them in a dir within a dir: /inc/widgets/my-widget-file.php
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, editor" }
Add custom field to all posts in specific category I want to bulk add a custom field (category) with value (photography) to all posts in a specific category (photography, with Category ID 5). I have used the code below to bulk add a custom field to all posts, but how can I narrow this down to a specific category? Anyone? This is the code I used for all posts: INSERT INTO wp_postmeta (post_id, meta_key, meta_value) SELECT wp_posts.ID, 'category', 'photography' FROM wp_posts WHERE wp_posts.post_status = 'publish'
You can use WordPress functions to do this and just run it once, a fast example would be. function wpse_85236_add_photo_field(){ global $post; $photoquery = new WP_Query('posts_per_page=-1'); while ( $photoquery->have_posts() ) : $photoquery->the_post(); if ( in_category( 'photography' )) { add_post_meta($post->ID, 'category', 'photography', true); } endwhile; } add_action( 'init', 'wpse_85236_add_photo_field' ); Remember to remove the function after it runs because you don't want it to run on every load.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, categories, custom field" }
modifying the comment form I see that there are lots of filters and things you can do to remove fields or modify them. I have found some useful ones on this site. I want to take it a step further because I want to do some things that there does not seem to be a filter for. Like removing the labels. At least I have not found one yet. I also need to remove the submit button and want to replace it with an actual button. For styling purposes. So I thought I could copy the comment_form function out of the wp-includes/comment-template.php file and put it in my functions.php file so that I could make any modifications I wanted. Problem with that is that WordPress throws you one of those previously declared functions errors. So I was looking for the filter or action to unregister that function so that I can use it in my functions.php file but I can't find it. Do you know how I can do this? I tried remove_action('comment_form'); but this did not work
That function is called directly in a theme, probably in `comments.php`. Remove the function call there, and use your own function with a different name. Be aware many plugins rely on the code in the native function. If you change too much, some plugin might break. You can edit the `label` element with a filter on `'comment_form_default_fields'`. Please do not remove them, they are important for screen reader users.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments, filters" }
Why WP_Query('showposts=5') shows only 1 post? I am trying to do a simple query to get the latest 5 posts into an unordered list, but this is only showing 1 result even though I have several posts. I even did an offset, but it shows the next post yet still 1 result. What am I doing wrong? <ul> <?php $the_query = new WP_Query('showposts=5'); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <li> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <p><?php the_content_limit(250); ?></p> </li> <?php endwhile;?> </ul>
`the_content_limit` does not exist in WordPress. You probably want something like `the_excerpt`. What's likely happening is your loop is working fine, but the call to an undefined function causes the program to error out, making it appear the the loop is not working. Look at the rendered HTML: you'll probably see a single, opening `<li>` tag, the link and an opening paragraph tag. `showposts` is also deprecated. Take a look in the codex: dropped in 2.1 Try this: <?php $query = new WP_Query(array( 'posts_per_page' => 5, )); while ($query->have_posts()): $query->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <p><?php the_excerpt(); ?></p> </li> <?php endwhile;
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, php, wp query, loop, query posts" }
Do i need to keep register_post_type in functions.php? I am creating several custom post types, do I need to keep the register_post_type calls in functions.php? I would assume that this would only need to be run the once then removed, or do I need to keep the calls there?
Yes, you need to keep it within `functions.php` and within the `init` hook, as it will have to register each time. It's not like with roles, where you can add it once and it's saved in the database.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types" }
The $post variable – Did I get the grasp of how the Backend actions get parsed? I was looking for a way to attach a custom meta box to the edit screen of a page at a specific template. I found and tried this here and from my actual point of view this can't work that way. Let me explain why I think so: To determine, whether I'm on a screen using a specific template I need reference the global $post. But since this function to create the meta box is hooked into the admin_init the global $post will not yet exist. So it has to put out an Error message, doesn't it? After those thoughts I tried to tie my meta_box_init function to edit_post, save_post and such. But the codex says, even they need $post to be set. So how could I achieve my page template specific meta box, really? Is there a clean solution?
As I've already wrote in question comments, at the very beginning of creating the new post or page first choose a template and save as draft. Meta box will appear after save if right template is used. <?php add_action( 'add_meta_boxes', 'my_add_meta_box' ); function my_add_meta_box() { // get template file name $template_basename = wp_basename( get_page_template() ); // check if right template is used if('my-template.php' == $template_basename) { add_meta_box( 'my_metabox', __('Metabox name'), 'my_display_metabox', 'page', 'normal', 'high' ); } } function my_display_metabox($post) { wp_nonce_field( 'my_metabox', 'my_metabox_noncename' ); // meta box HTML here }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "metabox, page template, globals" }
How to disable Jetpack modules such as Stats? I want to disable some of the Jetpack modules such as Stats in order to check if they make the web site slower or not. But I couldn't see an option to disable modules one by one. Of course, one can disable the Jetpack plugin as a whole. Is there a way to disable Stats module only? ![](
If you press the `"Learn More"` button for each Jetpack Module, you will get a `"Deactivate"` button showing up to the right. !Disabling the WP Stats Module There is also a fork call Jetpack Lite < > A NOT official "lite" fork of Jetpack plugin containing only Stats and WP.me Shortlinks modules. All other modules removed (files and code).
stackexchange-wordpress
{ "answer_score": 5, "question_score": 7, "tags": "plugin jetpack, statistics" }
Move content between custom post types I am importing a large amount of content from Expression Engine, the content in the other Expression Engine is all grouped together. I have created all the custom post types and taxonomies to organize the content better. However, Once I import the content to WordPress, I need to move the content into the newly created post types. How do I move content from one custom post type to another?
The information about post type is stored in wp_posts table in DB in column post_type - either post, page, attachement and other post types you've defined. So i quess you can use some SQL query in your case. Or you can write some script using WP_Query for fetching posts from cerain category (for example), and wp_update_post funtion setting post_type argument to desired post type...
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types" }
How to get date of post when using wp_get_recent_posts()? I get the latest posts this way: $args = array( 'numberposts' => '2' ); $recent_posts = wp_get_recent_posts( $args ); Then I loop through them and get information about the post this way: $recent_posts[0]["post_title"] How can I get the date the post was published?
You can see everything returned via php's `var_dump` or `print_r`: $recent_posts = wp_get_recent_posts(); echo '<pre>'; print_r( $recent_posts ); echo '</pre>'; This will reveal that the date is stored in `post_date`: foreach( $recent_posts as $recent ): echo $recent['post_date']; endforeach; Or to format the date, use php's `date` and `strtotime`: echo date( 'l F jS', strtotime( $recent['post_date'] ) );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "posts, date, recent posts" }
How to check if a certain theme option settings has already been set I am using the following lines to check if the theme setting already exist or set but it's not working: if (get_theme_mod('mysetting')==FALSE) { Aside from get_theme_mod, how to really check if the theme setting is already set? Thanks.
Maybe `get_option` will do the trick <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development" }
Query by post title I've used a custom post type for one of my website. Custom post type contains scratch card data along with some custom fields. I've developed an android application to manage those items from android device. In the android app, I want to keep search feature which will help admin users to search card numbers to manage those. I can use wordpress query to search by title. Code $args = array("post_type" => "mytype", "name" => $title); $query = get_posts( $args ); It can only provide result if I provide exact title. But I need to retrieve all items with similar title. Any suggestion?
You can use either search parameter of wp_query : Code $args = array("post_type" => "mytype", "s" => $title); $query = get_posts( $args ); Or you can get posts based on title throught wpdb class: global $wpdb; $myposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%s'", '%'. $wpdb->esc_like( $title ) .'%') ); Than you'll get post object in this form: foreach ( $myposts as $mypost ) { $post = get_post( $mypost ); //run your output code here }
stackexchange-wordpress
{ "answer_score": 30, "question_score": 14, "tags": "custom post types, wp query" }
remove_menu_page breaks "Add media" Using the the remove_menu_page function results in a really strange bug. By adding the code below in the functions.php file the integrated "Add media" widget starts to bug. function remove_menu_pages() { // Remove admin menu pages that are not used remove_menu_page( 'link-manager.php' ); remove_menu_page( 'tools.php' ); } add_action( 'admin_init', 'remove_menu_pages' ); When clicking "Add Media" while editing a post no files will show up under "Media Library", even tough the Media Library has plenty of files uploaded to it. If you try to upload a file, it will show up, but you won't be able to insert it into the WYSIWYG editor. If you close the "Add Media" window and then open it again the file is gone (but it's there if you navigate to the media library in the main navigation). Have anyone experienced this? Can anyone replicate it? Thanks!
It's because you've hooked it to the wrong action, it should be `admin_menu`, not `admin_init`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "media library, admin menu, bug" }
Making an input field required from WP's perspective Submitting a post comment without message leads to a white page with a clean WP error message "ERROR: please type a comment." Is it possible to achieve the same thing for input fields from a custom form? For instance, I've got my own custom contact page template containing a number of input fields, some of them I want to make required. How to get the same WP error message when those haven't been filled?
I believe yo are looking for **`wp_die`** which will Kill WordPress execution and display HTML message with error message. But the codex says: > It is not recommended to call this function very often and try to handle as many errors as possible silently.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "forms" }
Wordpress CSS head info - contents, expansions? AFAIK a `style.css` for Wordpress needs some comments at the top to be properly recognized, like: /* Theme Name: Cool Theme Theme URI: Description: Super cool theme */ Are there any restrictions regarding content? I've also seen people writing stuff in there like @author Michael Jordan @copyright 1990 by me What's up with that?
There is no reason to add something not listed in WP_Theme class `$file_headers` array because it simply will not be recognized. private static $file_headers = array( 'Name' => 'Theme Name', 'ThemeURI' => 'Theme URI', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Version' => 'Version', 'Template' => 'Template', 'Status' => 'Status', 'Tags' => 'Tags', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path', );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css" }
Remove "Edit Link" next to "Publish immediatley" when adding a new post I need to remove the **Edit link** next to **Publish immediately** as I don't want my user to schedule the post. How can I achieve this? Thanks!
Here is one idea to hide the _Edit_ link via CSS: function wpse85434_hide_editlinks() { if(!current_user_can('manage_options')){ // only for non-admins echo "<style>.misc-pub-section .edit-timestamp{display:none !important;} </style>"; } } add_action('admin_head-post.php','wpse85434_hide_editlinks'); add_action('admin_head-post-new.php','wpse85434_hide_editlinks'); I use `!current_user_can('manage_options')` so it will be visible for the admin. Before: !Before After: !After
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "scheduled posts" }
How to move existing Wordpress wp-content folder along with database to new server and new domain name? Running WP 3.5.1 on a LEMP stack (over at Linode) ... I have a wp-content folder for a WP site along with a full backup of the database. The URL of the site was something like: > test.example.com I want to get the site operational on my own server at: > test.mydomain.com And once the site is finished and DNS changes take effect, I want to have the site URL be: > myclientsdomain.com What is the preferred (and hopefully most straightforward way) of handling server moves and domain changes like this? I'm looking for a step-by-step answer, one that accounts for all the situations described above for both the files and database.
There's a pretty good step by step on moving WordPress in the Codex. It is what I follow when changing domains. Moving the files is pretty straight-forward. It is the hard-coded references in the database that are tricky. However, serialized search and replace will take care of all database changes. I've used the Velvet Blues plugin in the past, but the Search and Replace script is pretty top-notch.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "database, hosting, domain, site url" }
Create hooks based on an array of hook names? I have this idea where I would create a class that would take in a set of hook names then create them, for me to use when ever, and where ever. Currently the way to create a hook is we do something like: function some_hook_name(){ do_action('some_hook_name'); } And then from there we write some other function, well call - add_content and then pass it to the action as such: add_action('some_hook_name', 'add_content'); and there we go. But what if I wanted to create a class where I do something like: $array_of_hook_names = array( 'hook_one', 'hook_two', ... ) so that later on, I could do: add_action('hook_one', 'add_content'); Is there any way to do this? Could I just do something like: public function setup_hooks($array){ foreach($array as $hook_name){ do_action($hook_name); } } Ideas?
Your proposal is OK - you can see this in action even in the WordPress itself. See admin-ajax.php where you can find this piece of code: // Register core Ajax calls. if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 ); if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) ) add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 ); add_action( 'wp_ajax_nopriv_autosave', 'wp_ajax_nopriv_autosave', 1 ); if ( is_user_logged_in() ) do_action( 'wp_ajax_' . $_REQUEST['action'] ); // Authenticated actions else do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ); // Non-admin actions As you can see, the action hooks are generated dynamicaly...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "hooks, actions, oop" }
Add tinymce to widget textareas I've got several custom widgets which are extended from WP_widget. Many of these have textarea fields. I'd like to be able to apply a special css class to certain of these textareas in order to convert them to rich text areas with a basic TinyMCE toolbar control. How involved is this to do? I'd like to implement a solution that inherits most or all of its code from the WP core and just piggyback off that.
use the function wp_editor() to your textarea. This is the best and easy way, also usable fast forward.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "theme development, widgets, tinymce" }
Filter categories/tags to display in multiple metaboxes for selection in back-end My site uses a lot of categories and tags for author selection in the back-end. To make it more user friendly for authors I need to arrange the categories and post tags in numerous metaboxes for selection on the post edit screen. I would like to display some selected categories and their children in one metabox for author selection while other categories will go into a second and third metabox and so on. The same should apply to the tags. Can anyone point me in the right direction how to accomplish such a customization? Can I register new taxonomies which will include categories/tags based on their ID's and create new metaboxes displaying only those ID's? The Wordpress default metaboxes for categories and tags display all categories in one box. Thanks!
Yup! Just register a new taxonomy in your functions.php and it'll show up in your post editor. function my_custom_taxonomy(){ $args = array( 'settings' => 'here' ); register_taxonomy('Authors', 'post', $args); } add_action('init', 'my_custom_taxonomy'); <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, metabox, tags" }