INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Modify built-in post type properties I have an unusual situation where I need to make the built-in post type 'page' non-hierarchical. I printed the post type object with `var_dump(get_post_type_object('page')); die;` and I got this: object(stdClass)#164 (26) { ["labels"]=> ... } ["description"]=> string(0) "" ["publicly_queryable"]=> bool(false) ["exclude_from_search"]=> bool(false) ["capability_type"]=> string(4) "page" ["map_meta_cap"]=> bool(true) ["_builtin"]=> bool(true) ["_edit_link"]=> string(16) "post.php?post=%d" ["hierarchical"]=> bool(true) .... } How might I go about modifying the post-type object so that `["hierarchical"]=>bool(false)`?
This is a pretty late answer, but I was looking to do something similar and figured it out. I wanted to get nav_menu_items into an RSS feed, which required changing the built in nav_menu_item post type property publicly_queryable. Anyway, it was actually pretty simple, here's a generic function to do it: function change_wp_object() { $object = get_post_type_object('post_type'); $object->property = true; } add_action('init','change_wp_object'); And that's it. I've got it in a plugin. If you want to see the list of available properties to change, throw in echo '<pre>'.print_r($object, 1).'</pre>'; to get a nicely formatted output of all the properties. In your case you'd use $object-> hierarchical = false; Hope that helps someone!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "admin, pages, oop" }
Optimizing wp_get_attachment_image_src I'm working on WordPress gallery. I display images with wp_get_attachment_image_src function: foreach($slideshow_data['attachment_ids'] as $attachment_id) { $img_data = wp_get_attachment_image_src( $attachment_id, 'full' ); echo "<img src=\"{$img_data[0]}\" width=\"{$img_data[1]}\" height=\"{$img_data[2]}\">"; } Which results in over 140 database queries per page for large galleries. Of course this can be cached, but I feel that this is not correct way. My question is, am I doing something wrong? Thank you.
Usually for gallery post types with lots of attachments, you would do it like this: < Inside a "Wordpress Loop": <?php $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { echo apply_filters( 'the_title' , $attachment->post_title ); the_attachment_link( $attachment->ID , false ); } } ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "gallery" }
Backup localhost (wamp) database (phpmyadmin) from harddrive files on windows? For WordPress? Is it possible to backup files from a old hard drive without having access to phpmyadmin? Could someone point me in the right direction?
Don't know if it's the best way but her is **a** very simple way to do it: 1. Install a new copy of WAMP. 2. Copy the files from the old HD to you newly installed wamp `\bin\mysql\mysql...\data` folder. 3. Log in to phpmyadmin (that comes with WAMP) and create a dump of the database
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "backup, phpmyadmin" }
Disable a Custom Taxonomies default save mechanism I have a custom taxonomy X. I've specified that the UI should be shown (for debugging purposes), however the UI is now interfering with my automation. I have code that automatically mirrors terms into this taxonomy, duplicating it. Taxonomy X is effectively a copy of Taxonomy Y or a subset. This code is working almost perfectly, except that my assignment code is doing its work which is then undone by the WordPress UI code setting the terms for the post from the metabox. So how do I make the metabox showing Taxonomy X terms read only? AKA keep the metabox, but remove any save/edit/delete hooks attached to it? _**edit:** for reference, if `show_ui` is set to false in the registration of the taxonomy, and the UI for that tax is hidden, then everything works as expected. ( which itself is to be expected)_
Like Bainternet suggested - `remove_meta_box( 'tagsdiv-custom_taxonomy_id', 'post', 'side' );` to remove the default Metabox. If you want to still _see_ the terms. Then re-register the metabox with your own custom callback. This callback function can then mimic the function used to display the default metabox - but simply omitting any input forms /checkboxes which send any data. The function you'll want to mimic is: * For non-hierarchical taxonomies: < * For hierarchical taxonomies: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, automation" }
Removing admin javascript I'm having some trouble adding jquery-week-calendar to WordPress' admin interface using `add_menu_page` and other API methods. What I found out is that the default `jquery-ui` and other JavaScript references are interfering in the rendered calendar behavior. How can I remove these extra scripts from the admin interface? `load-scripts.php` is called a couple of times, and I can't seem to deregister the scripts that the admin components like tinyMCE and others are calling.
According to the `load-scripts.php` file, scripts that are not enqueued will not be loaded, so I don't need to worry about it when using hooks like `admin_enqueue_scripts` and the `wp_deregister_script` function. foreach( $load as $handle ) { if ( !array_key_exists($handle, $wp_scripts->registered) ) continue; However, my problem with jQuery week calendar was with the `wp-jquery-ui-dialog` style. So, to solve this problem I just had to: wp_deregister_style('wp-jquery-ui-dialog'); $scripts = array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position', 'jquery-ui-dialog'); foreach ($scripts as $s) wp_deregister_script($s);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "javascript, scripts" }
WordPress adding <br> tags into plugin content We've written a plugin that shows reviews upon usage of a shortcode. On some sites, Wordpress is adding `<br>` tags throughout the shortcode content, and others it does not. The shortcode works here (Nearby Now). The shortcode has tags inserted here (Dent Biz). There's a couple of articles here and here that recommend adding tho following code to the functions.php file. remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 12); I've tried this on the 2nd site above (Dent Biz), but it doesn't fix the problem. Also, I've tried disabling all other plugins on the site with no success. I would hope there was an easy way to prevent WordPress from molesting the html returned by the plugin. Any help would be appreciated!
It turns out that the Infocus theme was the culprit. Deactivating it immediately solved the problem. Their support forum recommended using the [raw][/raw] shortcode surrounding our shortcode, which allowed us to use our plugin with the Infocus theme. [raw][recentreviews radius="15" count="3" zoomlevel="10"][/raw]
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, plugin development, formatting, the content" }
I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that? My website is a multi author blog. I would like to give special promotion for the first 100 published posts in my blog? What is the proper way to implement it? I mean should i add some meta value for first 100 published posts and then query it later using that meta value? If yes can anyone tell me how? Thanks
Here is what I would do: Run an SQL query like so: SELECT * FROM `wp_posts` WHERE `post_status` = 'publish' AND `post_type` = 'post' GROUP BY `post_author` ORDER BY `post_date` ASC LIMIT 100 The above will give you the first 100 authors to have a post published. or: SELECT * FROM `wp_posts` WHERE `post_status` = 'publish' AND `post_type` = 'post' ORDER BY `post_date` ASC LIMIT 100 this will give you the first 100 published posts
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, query posts, post meta" }
Possible to get feed to return latest updated posts rather than latest published? Currently the RSS feed of my WordPress blog gives me the latest published posts. Is it possible to change this so that it returns the ones that are latest updated instead? So that the latest published are still in the feed, but if I update an old post it would pop up in a feed reader.
Try this (not tested) add to your functions.php of active Theme function wpse49312_alter_the_query( $request ) { $dummy_query = new WP_Query(); $dummy_query->parse_query( $request ); if ( $dummy_query->is_feed() ) $request['orderby'] = 'modified'; return $request; } add_filter( 'request', 'wpse49312_alter_the_query' ); From Alternative to query_posts for main loop?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "feed" }
URL Forwarding - wordpress links reverting back Say I built a site at test.example.com, and I now have it set up so that when you arrive at example.com you really see test.example.com, my problem is all the internal links created by wordpress want to go to test.example.com. Is it because Site Address (URL) under settings is still test.example.com? Any way/best way to fix this?
The internal links are all hard-coded; you'll have to do a search/replace in the database to fix them. This is a good script for search/replace that will go through your posts, widgets, everything: < Download the script, and upload it into your WordPress root directory (same path as wp-config.php). Surf to the script, then follow the steps to search/replace. When you're done be sure to delete the file from your website as it's not secure and could allow someone to access your database. Hope this helps!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "urls" }
How to query for most viewed posts and show top 5 Here is how I am getting the views for one post: function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } Let's say I want to find the most viewed posts from 5,000 posts and I want to show the top 5 most viewed posts. How can I make a query to achieve this?
View this section of the Codex to learn how to create a custom query: < Your query will be something like: $query = new WP_Query( array( 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'posts_per_page' => 5 ) ); By default, the ordering will be highest to lowest, thus giving you the "top" 5.
stackexchange-wordpress
{ "answer_score": 18, "question_score": 10, "tags": "wp query, query posts, query" }
Is there a limit to the length/size of serialized data that can be stored as user meta? I tried to store an array containing about 50000 keys and respective values to the user meta using update_user_meta. Since, this was only a test, I ran a for loop to generate the array. $test = array (); for ($i = 0; $i <= 50000; $i++) { $test[$i] = $i; } update_user_meta($user_id, 'test', $test); I ended up getting the error `WordPress database error: [MySQL server has gone away]`. Eventually, I was able to get it working with an array size of 48000 keys. Since update_user_meta converts arrays to serialized data before storing, is there a limit to the serialized data that user meta or post metas can handle? Or does this happen due to some other issue? I tried the timeout fix suggested here. But I am not sure if it is supposed to work for WP 3.3.1. or whether if at all it is solution to my problem. Please note I am using a local dev install using MAMP.
According to the DB schemea, the `meta_value` column is of type longtext, and that has a maximum size of 4GB, however you're unlikely to reach that. Eitherway storing large quantities of data in a single field is bad both from a practical point of view, a performance point of view, and data storage. I advise instead you use a custom taxonomy for this kind of data ( yes taxonomies aren't just for post objects )
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "user meta" }
wpquery via ajax I can reload my page and have php write a new **wpquery** and replace the content on my page, but I really don't want to deal with a new page load. Is there an _easy_ way to send a **wpquery** string (eg `"p=7"`) via **ajax**? Even if I have to make a custom php page to query, that's fine. I'm still new to wordpress so I wanted to make sure there's no easy way to do this before I start taking the "scenic" route. **Thanks.**
The accepted answer on this post: Ajax and autocomplete does an extremely good job of showing exactly how to integrate an ajax call within Wordpress.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, ajax" }
Modify loop but keep the original query, what am I doing wrong? I have a custom post type where I have a taxonomy `cities` and a term `berlin`. Archive can be seen at `example.com/cities/berlin` and it's rendered normally from the `archive.php` template. Now, I want to order them according to a custom field, `start_date` in this case, but still keep the original query around. So that when I navigate to `example.com/cities/newyork` the loop would still work as expected. This is what I have but I only get the `<p>Not Found</p>` in the end. Please help. Thanks :) <?php global $query_string; //to keep the original query around $args = array( 'orderby' => 'meta_value_num', 'meta_key' => 'start_date', 'order' => 'DESC' ); $posts = query_posts($query_string . $args); if (have_posts()) : while (have_posts()) : the_post(); ?> do stuff <?php endwhile; else : ?> <p>Not Found</p> <?php endif; ?>
You can't concatenate an array onto query_string like that. See Digging Into WordPress's post about looping for the right format. Alternately, you can use `array_merge()` like on the query_posts Codex page. Consider using `wp_reset_query()` after your loop. Sometimes you'll also see people save the original `$query_string` to a new variable, modify `$query_string`, and then reset `$query_string` after the loop like so: global $query_string; $old_query = $query_string // Modify your query, loop through it $query_string = $old_query;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query posts, loop" }
How can I see the error generated by plugin activation? I'm developing a plugin and upon activation, I get the following error: > The plugin generated xxx characters of unexpected output during activation How can I see what `unexpected output` is generated? I have turned on debugging, but it doesn't help: define('WP_DEBUG', true); if (WP_DEBUG) { define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', true); @ini_set('display_errors', 1); } **Update** FYI - I have checked that there are no spaces before and after `<?php ?>`. I've done some digging around and tested various solutions, but I'm still stuck.
If a plugin has the error output > The plugin generated xxx characters of unexpected output during activation then that only means that _there is some error output_. Sadly WP can't output anything more than this. Every error output sends a header (as `var_dump`/`var_export`/`print_r`/`print`/`error`/`printf` would output. ## In short: You won't get any more info unless you're diggin´ deeper into the plugins code. Your best bet are above ↑ mentioned functions that you could throw into the plugins code to get a _real_ error output. **Short:** Sorry to say that, but it is what it is... :/
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, errors" }
Custom Post Type & Meta Box - Displaying meta box information on front end? I've created a custom post type "projects" that has a meta box for additional information (client name, type of project, budget, etc). I'd like to be able to display this information on the front-end. The custom post type is available to be added to custom menus if desired ('show_in_nav_menus' => true), but when you view each project, all you see is the title and the description. Ideally, I'd like the meta data to show with the title and description in whatever theme that is being used for the site, but I don't know if that's possible. Is there a way to display the meta box information on the front-end without having to either (a) touch the theme files (since themes can change so I don't want to do that) or (b) calling my own function that returns my own page template for the projects (because then it won't use the theme that is active)? Thanks! ETA - This is all done within my plugin.
Solution: Inside a function, retrieve meta box field values using get_post_custom_values() and added it to $content passed to the function. Use 'the_content' in the add_filter.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, metabox, front end" }
How to set a Preset category for custom post types? For Posts you can have a preset category where all Posts fall if not specified otherwise (settings -> writing). Can this be done for custom post types that have a custom taxonomy? The `register_taxonomy` does not seem to offer parameters for that. Thanks again :)
Try hooking into the save_post action to check the custom terms when a post gets saved: add_action( 'save_post', 'set_default_category' ); function set_default_category( $post_id ) { // Get the terms $terms = wp_get_post_terms( $post_id, 'your_custom_taxonomy'); // Only set default if no terms are set yet if (!$terms) { // Assign the default category $default_term = get_term_by('slug', 'your_term_slug', 'your_custom_taxonomy'); $taxonomy = 'your_custom_taxonomy'; wp_set_post_terms( $post_id, $default_term, $taxonomy ); } }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "taxonomy" }
How to fix vanilla comments extra iframe space I am using the new vanilla comments on wordpress with my self hosted vanilla forums, but on every page, there is unnecesary iframe space. I was wondering how to fix that. My site is here and my forums are here. Between the submit comment and comments by vanilla link.
# UPDATE The frame element has a height of 1000px. I am not sure which file generates the comment form, but the height seems to be in that file. Simply delete `height=1000px` to remove the space. Also, if you want to remove the Vanilla credit and link, add `.vanilla-credit {display:none !important}` to your style sheet. # ORIGINAL I believe you are referring to the large space between the bottom of your post and the "Leave Comments" title to the comment textarea. If so, there is a pretty large bottom margin in the `.post` class in your style sheet. You can remove it by changing it to `margin:0`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, php, customization, comments" }
How to check a list or feed of all posts under a category and tag? Consider this question from the point-of-view of a visitor to a WordPress blog, and not as a WordPress blog admin who can edit those numerous PHP files. How can I see a list of all the posts under a category and a tag? Not clear? Let me explain with an example: > I have two categories -- _Social Media (social)_ and _Web (web)_ , and I have a tag _Tips and Tricks (tips-and-tricks)_. > > Consider that I use the tag frequently with posts under both categories. The question is, how can a visitor to my blog, check posts tagged "tips-and-tricks" and under "social" category? I am looking for a solution _similar to_ this: ` (which we use to combine rss feeds of multiple categories). Thanks.
Found it! Similar to how you'd do it with RSS feeds, you can do it like this: ` Where `6` is the category ID of _Social Media (social)_ category as per the example.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, query" }
How to add a new taxonomy link to the admin menu I am looking to add a new admin menu item from my plugin call "Tickers" under "Post", with the link similar to "Tags", but point to /wp-admin/edit-tags.php?taxonomy=tickers What I have so far is add_action('admin_menu', array($this,'admin_menu')); function admin_menu () { add_options_page(); } I am not sure what are the right parameters to pass to add_options_page. Any help would be much appreciated. **Edit** Answer provided below lead me to < which can generate the custom taxonomy functions for you.
The taxonomy admin page will be handled by WordPress once you register your custom taxonomy. add_action( 'init', 'create_ticker_taxonomies', 0 ); //create two taxonomies, genres and writers for the post type "book" function create_ticker_taxonomies() { // Add new taxonomy, make it non-hierarchical (like 'tags') $labels = array( 'name' => _x( 'Tickers', 'taxonomy general name' ), ... ); register_taxonomy('ticker',array('post'), array( 'hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, )); } The full options available to you regardin the taxonomy and its labels can be found on the Codex Page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development" }
Simply poll & Events Calendar plugins clashing I'm using two plugins that seem to clash: < < When both activated only the poll plugin shows in the admin menu but when it's deactivated the calendar plugin shows in it's place. Is there a way to get both plugins working together as they're exactly what I need. I'm running the latest version of WP. p.s It's more than likely that the problem lies with the poll plugin!
It _might_ be due to the position on the admin sidebar in Simply Poll. Go to simply-poll/lib/admin.php and on line 40 remove the `, 6` from the end of the `add_menu_page()` function and see what happens. I'll have a look at the other plugin as well to check what they are doing. **Simply Poll developer**
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, admin" }
Display posts and thumbnails with certain tags I want to display specific posts from an array with specific tags i.e. "Bolivia" and "Brazil" and then show the post thumbnail and permalink. This is the code I am using so far but as you can see I am not calling the tags. Thanks. <?php query_posts(array('category__in' => array(4), 'posts_per_page' => 4)); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $currentid = get_the_id(); ?> <div class="list-box"> <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($currentid, array(120, 100)); ?></a> <div class="list-box-title"><h3><?php the_title(); ?></h3></div> </div> <?php endwhile; endif; wp_reset_query(); ?>
See the WP docs for query_posts. Relevant excerpt: The following returns all posts that belong to category 1 and are tagged "apples" query_posts( 'cat=1&tag=apples' ); You can search for several tags using + query_posts( 'cat=1&tag=apples+apples' ); Or using the array version you're using, something like this: $args = array( 'category__in' => array(4), 'posts_per_page' => 4, 'tag' => array('Bolivia', 'Brazil') ) query_posts($args); String version for your case: query_posts('category__in=4&posts_per_page=4&tag=Bolivia,Brazil');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "tags" }
Custom Single Page Portfolio Theme I'm thinking about creating single page portfolio theme, but I'm a little confused on how this would be done based on the different sections on the single page. I'll explain what I would like to do and hopefully someone can help me figure this out. I'm just looking for guidance on what I should do to handle the different sections (maybe custom post types?) 1. Slider 2. Portfolio ( 4 Columns -- -- -- -- ) 3. About ( 2 Columns -- ------) 4. Contact ( 2 Columns ------ -- ) 5. Footer / Social Links If it is too much work for me I'll just pay to have this created, so if interested please leave a contact email and I will get back to you Thanks!
In the page editor switch to HTML mode and wrap each section of content around divs you want to be a column. <div class="col2w col2a">Col 1</div> <div class="col2w col2b">Col 2</div> <div class="col3w col3a">Col 1</div> <div class="col3w col3b">Col 2</div> <div class="col3w col3c">Col 3</div> Next use CSS to style them to look like columns.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "theme development, themes" }
WordPress Create Post from front-end I'm having to design an e-commerce site where users should be able to create a product from front-end. In WordPress, the product will simply be a post with custom fields like Price, Condition,....... Also, from front-end, the user should be able to upload pictures. I just need some advice from you guys. What would be the best-practice for this. I've not come across any e-commerce plugin that allow front-end posting of product. So can you please advise me
I like mrwweb's suggestion, but if you are trying to do it yourself / for free, you will have to do a few things: 1) Make a new template PHP file with the forms you will need to create a new product, create a new page and assign it the template you created 2) Create your custom post type or decide to use post meta instead for your extra fields 3) In your template, use PHP to process the form and do something like this to insert it as a post in the Wordpress database: $new_post = array( 'post_title' => $post_title, 'post_content' => $post_content, 'post_status' => $post_type, 'post_author' => $author_id, 'post_category' => $category, ); $new_post_id = wp_insert_post($new_post); add_post_meta($new_post_id, "product_type", "tshirt"); It's a lot more work than just that code above of course, just a starting point if you were going to write the solution yourself.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "custom post types, custom field, front end, e commerce" }
Change Default Custom Fields Metabox Name I found that the title of the meta box cannot change via the cctm plugin. It shows "Custom Fields" as default, which is pretty annoying to see. Image So I decided to change it in function.php, here is my code : add_filter('add_meta_boxes', 'change_meta_box_titles'); function change_meta_box_titles() { $wp_meta_boxes['my_post_type']['normal']['core']['cctm_default']['title']= 'Details';} But it failed to work, any idea?
You need to declare the `$wp_meta_boxes` array as global: global $wp_meta_boxes; If it still doesn't work try: add_filter('add_meta_boxes', 'change_meta_box_titles'); function change_meta_box_titles() { global $wp_meta_boxes; echo '<pre>'; print_r($wp_meta_boxes); echo '</pre>'; } to see what's going on (and to check where the title is). You should also **prefix your function names** to prevent a clash with WP or other plug-ins.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "title, metabox" }
Tracking post type in Google Analytics Is there an easy way to filter between posts and pages in Google Analytics? Page is listed as a Primary Dimension when I drill down to Content but I'm not sure if that includes posts as well.
It's not tracked by default. Yoast's WordPress SEO plugin allows you to track post types (and categories and authors...) as a custom variable.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "google analytics" }
Hourly WP schedule, do I need at least 1 visitor hourly? I am planning to schedule an hourly task from my wp plugin, as I understand these tasks are triggered by visits to the website. So for an hourly task I will need at least one visitor hourly. Does it matter at what time of the hour the visitor comes? For example if there's a visitor at 1:05, and another at 2:55, the 1 and 2hs task wont be missed?
As you've noted, cron jobs are only fired when someone visits your website. WordPress checks if they are any events that have been scheduled before 'now' that have not yet occurred - and runs them. Importantly with events that are recur according to a regularly pattern (say hourly) - their occurrence is relative not absolute. That is, once your event triggers it will be scheduled again in an hour's time (rather than being schedule for 1:05, 2:05, 3:05) - of course with no guarantee that it will actually run in an hours time. In fact with recurring events WordPress only keeps one occurrence saved. Once that occurrence is trigged it is replaced with the next one.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "plugin development, cron, wp cron" }
Change Site Title and Description html tags if not home page For the purpose of good HTML structure, accessibility and SEO I'd like to change the site's title and description from H1 and H2 to P when appearing on any page other than the homepage. A conditional statement logic would be something like; when not homepage change site title and description to Site Title and Description . Thanks!
<?php if (is_home() || is_front_page()) { $header_tag = 'h1'; } else { $header_tag = 'h2'; } ?> <<?php echo $header_tag;?>><?php the_title();?></<?php echo $header_tag; ?>> Expanding on what Stephen Harris said, here is a useable example. Lots of different ways to use same code function.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "seo, title, homepage, conditional tags, description" }
When is admin_init Action ran? I have this function below that is called with the `admin_init` Action function my_flush_rewrites() { global $wp_rewrite; $wp_rewrite->flush_rules(); } Like this add_action('admin_init', 'my_flush_rewrites'); I am curious, when is this called? Is this called on every page load? Hopefully not
From the Codex: > admin_init is triggered before any other hook when a user access the admin area. This hook doesn't provide any parameters, so it can only be used to callback a specified function. So yes, it's run on every _admin_ page load.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 6, "tags": "actions" }
WP_Query with 2 genres I'm working with a custom post type and trying to get a query working that includes 2 genres (a custom taxonomy). I have this, which works for a single genre (I don't want to display the widget currently being viewed in the list, the 'post__not_in' takes care of that). $myposts = new WP_Query( array( 'post_type' => 'widgets', 'post__not_in' => array($wp_query->post->ID), 'genre' => 'styleA' ) ); But I'm having trouble when I try to make a list that includes 2 genres. I've tried various versions of this: $myposts = new WP_Query( array( 'post_type' => 'widgets', 'post__not_in' => array($wp_query->post->ID), 'genre' => array('styleB', 'styleC') ) ); Everything I've read in the Codex seems to use a syntax like this, anyone know where I'm going wrong? Much appreciated.
Something along these lines should work: $myposts = new WP_Query( array( 'post_type' => 'widgets', 'post__not_in' => array($wp_query->post->ID), 'tax_query' => array( array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => array( 'styleA', 'styleB' ) ) ) ) ); I'm not sure if you need to add `'relation' => 'OR',` after **line 4** , so try it with/without that (i.e. before the `'tax_query'...` line).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
How can I modify the header of RSS feed items? Specifically I would like to change the value of `<dc:creator>` in the feed items. In order to display the site name instead of the post author. I'm able to hook into `the_title_rss` , `the_excerpt_rss` and `the_content_feed`, but can't find how to change the header elements of a feed item.
this value comes from the template `tag the_author()`. You can also filter this. But it is important, that you check, that the filter only work on the feeds; see the follow example at the check for `is_feed()`. After this i change the autor name only, if the string has the value 'name_xyz'; here is the point that you change your data from your requirements. I write from scratch, don't tested! add_filter( 'the_author', 'fb_change_fead_creator', 10 ); function fb_change_fead_creator( $text ) { if ( ! is_feed() ) return; if ( 'name_xyz' == $text ) $text = 'my new name'; return $text; } Best
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "hooks, author, feed, headers" }
Get moderation notifications on one post only I'm running a web based community using wordpress multi-site and buddypress. All users are invited by existing users so no spam accounts exist on site. Therefore we feel no need to moderate logged in users. Since doing this we have found that from now on all moderation requests come from spam attempts. So I have turned off email notifications for moderation. One problem, I have a contact page that currently uses comments for non-members to send a message requesting an invite or otherwise get in contact. Is there any way I can switch moderation notifications on for just this page?
I solved this issue in the end without using any plugin. The solution works because this is a multi-site install. The procedure is quite simple and painless. 1. I created a 'contact' subsite on the subdomain ' 2. I moved the contact 'page' from the main site to the sub site. 3. I enabled comments on this new page, both in wordpress admin, and in the theme. 4. I made the contact page the default home page for the contact site. 5. I changed all links on the main site to the 'contact' form to this new page. 6. I deleted the old page. I receive email notifications for the 'contact' but not the main site.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, notifications, moderation" }
Include file in plugin file I have a working plugin with many functions in it. I want to break the plugin into several file. I removed some functions and place it in a file called activate.php k7Course.php. Then in the file k7Couses.php i include as below: /* Plugin Name: k7 Course Management Plugin URI: Description: A plugin to manage k7 Courses Display Version: 1.0 Author: Noor Author URI: License: GPL */ require_once('activate.php'); The problem is that the code in activate.php in being included but as raw text because i see all the content of activate.php in the admin menu. Also the function are not being executed
It sounds as though your include file activate.php does not have the opening/closing php tags. Be sure to open activate.php and ensure it has the `<?php` at the beginning of the file, and the `?>` at the end.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, include" }
PHP files included within functions.php don't work from admin area I've split my functions.php into multiple files using `require_once`, which works perfectly. However when I add admin functionality (extra panels) in one of the included files, it doesn't work? It's making me put the code in functions.php which I don't want to do. This is the top of my functions.php <?php error_reporting(E_ALL); ini_set('display_errors', True); // Includes require_once('includes/admin.php'); // Admin stuff
The problem here is that you're not including `yourtheme/includes/admin.php`, you're actually including `wp-admin/includes/admin.php`, so pass a full path to the require statement rather than a relative one e.g.: require(get_template_directory().'includes/admin.php');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "include" }
A way to change image urls in post to cdn image url? due to some reason my hosting company isn't able to fix if i use w3 total cache or w3 super cache for caching my site's sql usage keeps on peaking.... and on high spikes servers gets laggy and down sometimes. For that i have to use hyper cache plugin for cache as it works perfect, but this plugin doesn't support cdn .. i have bought a cdn service from maxcdn but for that i wud have to use w3 total cache or super cache... So i am looking for a way to automatically change the post images url from for example : < to < is it possible ? if yes please help. Thanks in advance
You can parse via regex for images in `the_content`; but is always load and slowly. Maybe you change the url of images, after `post_save` in database or change the current posts inside the database and create an custom CDN. Its the fast way and all caching plugins has the break, that she must parse the content. For background an custom CDN in WP see this answer.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "images, urls" }
How to remove_filter that filters iframes in posts? Which filter if removed allows iframes to be inserted into wordpress posts?
This filter does not. This feature is disabled in the visual editor TinyMCE. function wpse49619_change_mce_options($initArray) { $ext = 'iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src]'; if ( isset( $initArray['extended_valid_elements'] ) ) { $initArray['extended_valid_elements'] .= ',' . $ext; } else { $initArray['extended_valid_elements'] = $ext; } // maybe; set tiny paramter verify_html //$initArray['verify_html'] = false; return $initArray; } add_filter('tiny_mce_before_init', 'wpse49619_change_mce_options'); Also you can use examples from WPEngineer how to enhancement TinyMCE.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, tinymce, wysiwyg, filters" }
How do I write this SQL statement for Posts written in last 24 hours? Someone gave me this SQL code to count the number of posts (of post_type 'mixtapes') in the last 7 days. I tried to convert it to 'in the last 24 hours' as well, but it's giving the wrong number. Here's his code which works for 7 day period: $querystr = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'mixtapes' AND post_date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) LIMIT 0, 30"); if (0 < $querystr) $querystr = number_format($querystr); Here's my code for 1 day period which gives wrong answer $querystr = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'mixtapes' AND post_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY) LIMIT 0, 30"); if (0 < $querystr) $querystr = number_format($querystr);
Personally, I'd generate the date in php using the PHP `Date` class and then $date->sub(). With a few more lines of code the query will read: ... WHERE post_date >= ".$date." ...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "custom post types, posts, loop, database, mysql" }
Remove Personal Options section from Profile I want to hide/remove the Personal Options in the **Your Profile** (`wp-admin/profile.php`) admin page. I am aware that solutions for this exist, but I they use jQuery to do hide this section. This works, but when a user has JavaScript disabled in their browser, it will show up again. Therefore it is not a proper way to remove Personal Options. Is there a way to remove the Personal Options section from the HTML source of the page? This means no jQuery or CSS hacks, or core file modification.
This should do the trick // removes the `profile.php` admin color scheme options remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' ); if ( ! function_exists( 'cor_remove_personal_options' ) ) { /** * Removes the leftover 'Visual Editor', 'Keyboard Shortcuts' and 'Toolbar' options. */ function cor_remove_personal_options( $subject ) { $subject = preg_replace( '#<h3>Personal Options</h3>.+?/table>#s', '', $subject, 1 ); return $subject; } function cor_profile_subject_start() { ob_start( 'cor_remove_personal_options' ); } function cor_profile_subject_end() { ob_end_flush(); } } add_action( 'admin_head-profile.php', 'cor_profile_subject_start' ); add_action( 'admin_footer-profile.php', 'cor_profile_subject_end' ); Also, don't forget to mark your previous questions as solved :)
stackexchange-wordpress
{ "answer_score": 25, "question_score": 13, "tags": "profiles" }
query inside main query order issue I'm trying to access the following shortcode in a simple page, with [featured/] function mytheme_featured() { $my_query2 = new WP_Query('category_name=featured&showposts=1'); while ($my_query2->have_posts()) : $my_query2->the_post(); return '<h3 class="entry-title"><a href="'.the_permalink().'" title="Permalink to '.the_title_attribute( 'echo=0' ).'" rel="bookmark">'.the_title().'</a></h3><div class="entry-content">'.the_excerpt().'</div>'; endwhile; } add_shortcode( 'featured', 'mytheme_featured' ); However, the content of that post is displayed at the top of the page, instead of the location given to the shortocde, which is below the first paragraph, inside the box with the red border. Any thoughs on why this happens?
the_title(), the_excerpt() and the_permalink() prints the output at once but the shortcode function is supposed to just return the output. You can use get_the_title(), get_permalink() and get_the_excerpt() instead.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query" }
Check if there is an post to be published in future I need to check if there is an post to be published in future. I want to use WP functions, no directly access to database via mysql_query. Has anyone some sample of code?
You can use `get_post_status()` within a query to get `future` posts. <?php $args = array( 'post_status' => 'future' ); $my_query = new WP_Query( $args ); while ($my_query->have_posts()) : $my_query->the_post(); ?> <!-- Do stuff... --> <?php endwhile; ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, publish" }
How To Remove The "Delete" Theme Option In Dashboard How do I remove the option to "delete" a theme in the admin dashboard? I built a site for clients with several themes they can choose from and i don't want them to accidentally delete a theme. Thanks!
You need to remove the `delete_themes` capability from those users. The easiest way would be to create a custom user role, based on the "Administrator" role, but omitting relevant caps, such as `delete_themes`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "themes" }
What's the proper way to find and remove duplicate images from posts and the media library? I just exported a largish WP blog from MediaTemple to PHPFog. I used the standard WordPress export and import plugins. For some unknown reason all of my media assets have been duplicated. I now have twice as many images per post. If an original file was called "Lot-44-Warrens.jpg" it now has a duplicate called "Lot-44-Warrens1.jpg" Both files are attached to the same post. I now have many duplicate images across about 250+ posts. So my question is how do I remove said duplicates from the media library and from the posts? I tried to search the media library with "*1.jpg", but it didn't work. Looking for a neat solution that doesn't mean removing each dupe manually. Perhaps there is a MySQL query I can run to remove the dupes from the library and the posts? The site in question is: < .
combining the two answer on this page, I found this worked. $args = new WP_Query(array( 'post_type' => 'post', 'posts_per_page' => -1 )); $loop = new WP_Query($args); while($loop->have_posts()) { the_post(); $args2 = array( 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image'); $attachments = get_posts($args2); if($attachments) { foreach ($attachments as $img_post) { if( ((strpos($img_post->guid, '1.jpg')!== false) || (strpos($img_post->guid, '1.gif')!== false) || (strpos($img_post->guid, '1.png')!== false))){ $stuff = $img_post->guid; wp_delete_attachment($img_post->ID); } } } } wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 3, "question_score": 7, "tags": "images, media library, duplicates" }
How do I display logged-in username IF logged-in? I'm working on creating some text that says 'Login' to users that are not logged in, and the user's username or display name when logged in. It seems like it should be an easy problem to solve, and I've found the following two bits of code on the wordpress codex that each do half of what I am looking for, but I haven't figured out how to combine them (without breaking the site). Is this the correct direction, or way off base? **To check if the user is logged in and display something different depending:** <?php if ( is_user_logged_in() ) { echo '{username code here}'; } else { echo 'Login'; } ?> **To get and display the current user's information:** <?php global $current_user; wp_get_current_user(); echo 'Username: ' . $current_user->user_login . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; ?>
This seems to do what you need. <?php global $current_user; wp_get_current_user(); ?> <?php if ( is_user_logged_in() ) { echo 'Username: ' . $current_user->user_login . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; } else { wp_loginout(); } ?>
stackexchange-wordpress
{ "answer_score": 50, "question_score": 21, "tags": "users, username" }
get query's query string By the time index.php runs, it seems as though there is already a query populated. How can I find out what that query's query string is? eg. `new WP_Query([query string is here])`
Take a look at `global $query_string;`. Or `var_dump( $GLOBALS['wp_query'] );`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "wp query, query posts" }
Aggregate multisite RSS and restrict certain content As the title says, I've got a multi-site setup with 18 sites and would like to combine the RSS feeds from all sites into the root site's feed. The other feeds can still exists, that's not a problem. Additionally, I'd like a way in the admin (on page/post edit, perhaps), to exclude certain posts from the feeds. In addition to a custom plugin containing all the specialty widgets and core function overrides, we're using a heavily customized theme as well. I'm using this code in my functions.php to pull all content types into RSS: function custom_post_feeds($qv){ if (isset($qv['feed'])) $qv['post_type'] = get_post_types(); return $qv; } add_filter('request', 'custom_post_feeds'); Any ideas?
The bottom line is that you'll need to have all the post content in one place in order to be able to form it into a single feed. (Querying efficiently across 18 different post tables is more or less impossible.) My go-to method is to use the Sitewide Tags plugin < which allows you to designate a "tags" blog, where a copy of every post on your network will be saved. You could set your main site as the "tags" blog, but it'll mean that you have to rig something up to keep the duplicated content out of your main feeds. (Such as a filter on guid, which the SWT plugin uses to point back to the original content.) Alternatively, you could just set up a separate "storage" blog for this purpose, and then point your RSS links to it (or `switch_to_blog()` in the context of your primary site).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "multisite, rss" }
Is it possible to disable certain user roles from creating tags? As a site admin, I'd like to have control over things. I'd like to prevent my contributors and authors ( who generate content for me ) from creating new tags. I don't want that tag taxonomy to turn into a zoo! Especially when you know that wordpress creates separate terms for apple and Apple! I give them a while list ( of 1000 tags that I want them to cover ) and that's it. They cannot come up with the 1001st. How do I achieve that so that my authors just pick from what I give them?
This Wordpress Answers thread has exactly the information you are looking for - Plugin to restrict non-admin user to existing tags Simply change "administrator" to whatever you need.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "categories, admin, tags, author, admin menu" }
how to replace get_template_part('loop','tag') with explicit styled version? So my theme has a tag.php, that contains this line: `get_template_part('loop','tag');` that runs the loop and spits out the tag entries. I'm modifying it to include post thumbnails (using if(has_post_thumbnail()) { the_post_thumbnail() }), but have run into a need to add more styling. to do this I need to get access to the code that `get_template_part()` is spitting out. i know i should be able to do this somehow by creating my own loop in loop-tag.php or some such thing, but can't find an example. can someone give me a simple example of a loop-tag.php that would break the functions of `get_template_part('loop','tag')` into it's components?
I think you misunderstand the purpose of `get_template_part()`. It is a wrapper for `locate_template()`, which itself is just a wrapper for `include()`. By calling `get_template_part( 'loop', 'tag' )`, you are telling WordPress to look for/include a file based on the following priority: 1. Child Theme `loop-tag.php` 2. Parent Theme `loop-tag.php` 3. Child Theme `loop.php` 4. Parent Theme `loop.php` **If you need to modify the markup of the loop itself, then you simply need to modify the appropriate file, according to the above priority list - e.g.`loop-tag.php` in your Theme or Child Theme.** You may need to _create_ this file; if so, copy `loop.php`, name the copy `loop-tag.php`, and edit as necessary.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, tags, get template part" }
Cannot Modify Header Info Error on updating User Profile I keep on getting this error on updating a user: PHP Warning: Cannot modify header information - headers already sent by (output started at /wp-admin/includes/update.php:134) in /wp-includes/pluggable.php on line 866, referer: /wp-admin/user-edit.php?user_id=4&wp_http_referer=%2Fwp-admin%2Fusers.php Any ideas why? My header.php does not seem to start with an empty space, but just with `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " And, besides, this seems to be more backend related... **Solution** Somehow `pluggable.php` or `update.php` or one of the user edit files got corrupted. After the upgrade to 3.3.2 all good again. All users can be updated again within getting stuck in error reports.
It is usually because there are spaces, new lines, or other stuff before an opening tag, typically in wp-config.php. This could be true about some other file too, so please check the error message, as it lists the specific file name where the error occurred (see the link below for more info on "Interpreting the Error Message"). Replacing the faulty file with one from your most recent backup or one from a fresh WordPress download is your best bet, but if neither of those are an option, please this codex: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "users, pluggable" }
Is there a plugin for uploading files such as PDF files? I want to put my lecturers for my students as PDF files in my wordpress, is it possible?
Yes it's possible. File upload is a default feature of WordPress. You don't need to use plugins for this. Read how to upload files in WordPress.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, pdf" }
Confusion about how to use Custom Post Types, Custom Taxonomy or Category? I've been reading about Custom Post Types, Custom Taxonomy and Category but I'm still getting some confusion. I want to build somewhat like an ecommerce site just to understand it better. Say I've a problem like this Products --Computer --Operating System --Linux --Win 7 --RAM --less than 1 GB --1 GB --2 GB --Car ---Brand --- BMW --- Ford ---Color --- Red --- Blue Price From <TextBox> to <TextBox> My Solution will be somwhat like this: 1. Product is a custom post type 2. Computer and all others are hirarchical taxonomy 3. Price is a custom field for product what do you think, am I go the right track or can you correct me??
I'd say your on exactly the right track. Since you're in the process of reading up on CPTs and such, I'd highly recommend giving this 4-part tutorial series a read: Reusable Custom Meta Boxes, wp|tuts+
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy, custom field" }
Filter to remove the default password on "Your Profile" page Whenever I go to my "Your Profile" page to edit any of the settings other than the password, I have to manually empty out the password field to avoid errors/nags. Is there a filter I can place in functions.php that will empty the password field by default?
By default the password fields should appear "empty" on the "Your Profile" page. Make sure your Wordpress installation is up to date and try deactivating any plugins that extend the user profile page and commenting out any code in your functions.php file. There is most likely a conflict with one of these plugins.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, users, profiles" }
Malware in header.php Four different websites got infected and been blocked by Google, and after a quick look, I've noticed this just before wp_head(): <?php #d93065# echo(gzinflate(base64_decode("tVVNj5swEP0... (edited out) hH5m7L/5+/gM="))); #/d93065# wp_head(); ?> I have cleaned the code but this reappeared after a few hours. Then again and again. I thought that timthumb is the culprit, but this happened on a WordPress without timthumb aswell as I've scanned it previously with timthumb vulnerability scanner. There's nothing suspicious in htaccess, wp-config and the files everyone is talking about, from wp-includes, have checked all the js files, nothing, nothing, nothing. **What could it be, how do I get rid of this?**
Sorry to hear. You may want to look through the steps and suggestions in this WP Answers post: Verifying that I have fully removed a WordPress hack?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "timthumb, virus" }
How to add a class to meta box When adding a metabox, i.e.: add_meta_box( 'metabox_id', 'Metabox Title', 'my_metabox_callback', 'page', 'normal', 'low', array( 'foo' => $var1, 'bar' => $var2) ); how do I add a `class` to it for css styling? I'd like to avoid having to call each `id` in the style rule for metaboxes that contain elements having the same style.
Just add the class to the markup you are generating in the callback.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 6, "tags": "metabox" }
How can I query the db to access current post information? Alright y'all. I want to dynamically display the information of the 2 most current posts to the screen. So far I have only been able to get results by hard coding the ID into the query. Is there a way to retrieve this data dynamically? query_posts('showposts=2'); while (have_posts()) : the_post(); ?> <?php $x = get_the_ID(); echo $x; $postStuff = $wpdb->get_row('select * from wp_posts where ID = "$x", ARRAY_A); print_r($postStuff); ?> <?php endwhile;?>
The correct way: $my_query = new WP_Query('posts_per_page=2'); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php global $post; print_r($post); // <-- this is your postStuff ?> <?php endwhile;?> <?php wp_reset_query(); ?> Normally, you dont't need to globalize the post. There are helper functions that should be used instead to fetch information from the current post
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "database, query, id" }
Add something to beginning of the content I'm using add_action('the_content', 'myFunction', 10) to append data to the end of the content. How can I place content at the beginning of the content?
`the_content` is also a filter, into which the content is passed as an argument. You simply prepend your content and then return like so. add_filter('the_content','prepend_this'); function prepend_this($content) { $content = "string to prepend" . $content; return $content }
stackexchange-wordpress
{ "answer_score": 9, "question_score": 5, "tags": "actions, the content" }
Remove Comments section from certain category posts I'm trying to simply disable my comments section from one of my categories from showing up on my posts. How do I do this? Whats the code and where do I insert the code from a general standpoint? Thanks
1.In your single.php find the location where it include the comment template. 2\. Then Check the category name of the post. 3\. Use if else statement to check if its the category u want/not to display the comment and include it by desire.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, comments" }
Remove the Edit button in posts for permalinks on certain user roles? WP 3.3 I am using Wordpress 3.3.2 with the following plugin: \- < The plugin works perfectly but the author said there is currently no way to achieve this from the plugin, So I am wondering if there is either another plugin or any code modifications I can make to achieve them. 1. I created a custom user role Called "Member" 2. I applied certain permissions so the user can only sees options to make posts in the backend. 3. When making a post, the user does not see the "Edit" option to change the permalink. 4. The problem comes after the user submits the Post. Right below the post title field it shows the permalink and shows an "Edit" button which allows the user to change the permalink. Is there any way to remove either the "Edit" button so they can't edit the permalink, or removing that entire line altogether so the permalink doesn't show for them at all? Thank you in advance!
You could do something like (in your functions.php file); if(current_user_can('member')){ add_filter('get_sample_permalink_html', 'perm', '',4); function perm($return, $id, $new_title, $new_slug){ $post = get_post( $id ); if( ! $post || ( $post->post_type !== 'testimonials' ) ) { return $return; } return preg_replace( '/<span id="edit-slug-buttons">.*<\/span>|<span id=\'view-post-btn\'>.*<\/span>/i', '', $return ); } To give credit where credit is due, everything between ~~`if( $_GET['role'] =="member" ) {`~~ and ~~`}`~~ ...is directly taken from this Question & Answer HERE courtesy of **Jonathan Wold** # UPDATE The conditional if statement of; `if( $_GET['role'] == "member" ) {//code here }` was replaced with, **`if(current_user_can('member')){ //code here}`** ...in this instance.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, permalinks, admin, user roles" }
Displaying wp menus by name without using theme locations I used wp menus in the past but always registering a location and then using: <?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?> To display a menu on that location on my theme I would first create a menu, and then assign it to that location. Well now what I would like to do is to create all the menus I want using some standard name like my-menu-1, my-menu-2, my-menu-x. And then I want to display those menus on my theme but without using any location, just printing them using code identifying them by name. **How could I do that?**
Umm u can do that easily. And this is the way I do how i register my menu in functions.php add_action('init', 'register_custom_menu'); function register_custom_menu() { register_nav_menu('custom_menu', __('Custom Menu')); } Then in ur admin panel u create different menu by ur desired name. And get the menu where ever u want like this. EX:- if I made two menu in admin by name "Menu 1" and "Menu 2" wp_nav_menu(array('menu' => 'Menu 1')); wp_nav_menu(array('menu' => 'Menu 2'));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "theme development, menus, themes, navigation" }
Wordpress adding in anchor elements when I save a page in html editor This page I am editing in the html editor. I pasted in my list from my text editor. You'll notice that the second last list item is all a link, thats because wordpress has taken it upon itself to wrap the whole thing in an empty tag! Why is it doing this and more importantly, how do I stop it? FYI here is the relevant ul <ul class="company-details"> <li>Target Health & Fitness</li> <li>7 Sheffield Road Holmfirth HD9 7BW</li> <li>01484 681000</li> <li><a href="mailto:[email protected]">[email protected]</a></li> </ul> inside that wordpress has added an anchor, if you inspect it using inspector or firebug. I've added these filters thinking they'd work but they haven't remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' );
I don't remember which one, but there is probably a conflict with tone of your plugins. I had the same issue in the past. Deactivate all of you plugins, then go through and reactivate them one by one.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "html editor" }
Unregister Nav Menu from Child-Theme I like to use the Starkers Theme and build child-theme. So, I`d like to remove the this primary menu Starkers (functions.php) function starkers_setup() { // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'starkers' ), ) ); } endif; My child-theme functions.php looks like this: unregister_nav_menu( array( 'primary' => __( 'Primary Navigation', 'starkers' ), )); // my new nav register_nav_menus(array( 'primary_navigation' => __('Main', 'starkers'), 'utility_navigation' => __('Meta', 'starkers') )); But it doesn´t work for me. What´s wrong? Thanks
The Starkers theme setup is hooked to `after_setup_theme`, at a priority of `10`. So you basically have to wrap the unregister function inside another function (child themes functions.php file) and add it _later_ than the parent themes setup function, so it gets first added by the parent and later on removed by the child. function wpse_remove_parent_theme_locations() { // @link unregister_nav_menu( 'primary' ); } add_action( 'after_setup_theme', 'wpse_remove_parent_theme_locations', 20 );
stackexchange-wordpress
{ "answer_score": 12, "question_score": 7, "tags": "menus, user registration, filters" }
Unregister sidebar from Child-Theme I like to use a child-theme. The parent functions.php function starkers_widgets_init() { // Area 1, located at the top of the sidebar. register_sidebar( array( 'name' => __( 'Primary Widget Area', 'starkers' ), 'id' => 'primary-widget-area', 'description' => __( 'The primary widget area', 'starkers' ), 'before_widget' => '<li>', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>', ) ); // Area 2 ... My child-theme functions.php function xtreme_unregister_sidebar() { unregister_sidebar('primary-widget-area'); } add_action( 'childtheme_sidebars', 'xtreme_unregister_sidebar' ); But doesn´t work for. Thanks
Check the code bellow, I think that should work. add_action( 'after_setup_theme', 'remove_default_sidebars', 11 ); function remove_default_sidebars(){ remove_action( 'widgets_init', 'starkers_widgets_init' ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "sidebar, child theme" }
wp_insert_term does not insert description. I'm using this code. I cannot figure out what the heck is wrong with it? $args = array( 'description',"My Desc", 'slug' => "My Slug", 'parent' => 0 ); $result = wp_insert_term("Term1", "category", $args); The result is that term is added, term_taxonomy is added. Slug is added. But the darn description is skipped. wp_terms: term_id name slug term_group 1 Uncategorized uncategorized 0 2 Blogroll blogroll 0 3 Term1 my-slug 0 wp_term_taxonomy: TT_id T_id tax description parent count 1 1 category 0 0 2 2 link_category 0 0 3 3 category 0 0
I was having the same problem the other day, due to a completely different typo ;) $args = array( 'description' =>"My Desc", 'slug' => "My Slug", 'parent' => 0 ); $result = wp_insert_term("Term1", "category", $args); Note the corrected 'description' element in the $args array.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "description, terms" }
Temporally disable password to login with empty password? Does someone knows what part of wordpress code would I have to modify to be able to just enter into the admin panel without having to login? I need to work on a site but I wont have admin access until a few day (when my friend comes back from vacations), but I do have FTP access (only FTP, no cpanel or any other type of panel to get into the db and change the pwd) and have his permissions to do whatever I need to login. I checked wp-login.php file but couldn't find what to modify to allow me to login. Does someone knows what file shoul
I have not tried it, but this thread on stackoverflow.com seems to be what you need - Create new admin, wordpress
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "login, password, wp login form" }
Best Way to Query Custom Taxonomies Used on Custom Post Type I have a custom post type and a custom taxonomy located in a plugin. In writing my output loop for the CPT, I'm trying to output all the custom tax items assigned to the CPT items at the top of the page before outputting each individual CPT item. This is what I'm hoping to achieve: tax 1 | tax 2 | tax 3 | tax 4 ... CPT 1 CPT 2 CPT 3 ... I assume `wp_get_object_terms()` is the best way to get at the tax items, but I have to pass in the `$post->ID` or, in my case, an array of ID's as a parameter. Is there a way to write only 1 loop which would grab the IDs, do its thing and them move on to output the CPT items, or do I have to write 2 loops, 1 which first builds the array of CPT post ID's to pass into the function and then a 2nd which outputs the CPT items? Am I missing something else entirely? Thanks for your help!
Yes there is a way using only one loop but that can be messy and have on resources for large amounts of data, To do that you simple store all of the output as a variable and only output after you finished your loop, ex: $tax_array = array(); $output = ''; while ( have_posts()) { the_post(); $output .= '<div class="item">'; $output .= '<div class="item_title">'.get_the_title().'</div>'; $output .= '<div class="item_content">'.get_the_content().'</div>'; $output .= '</div>'; $temp = wp_get_object_terms($post->ID,'tax_name'); $tax_array = array_merge($tax_array,(array)$temp); } so after this single loop you have all of the items output in `$output` and `$tax_array` holds an array of all terms that you need.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, custom taxonomy" }
why does WordPress need two cookies for auth/login I can see two cookies: auth and login cookies in wordpress. Why do we need two? I think one is enough.
"On login, wordpress uses the wordpress_[hash] cookie to store your authentication details. It's use is limited to the admin console area, /wp-admin/ After login, wordpress sets the wordpress_logged_in_[hash] cookie, which indicates when you're logged in, and who you are, for most interface use. Wordpress also sets a few wp-settings-{time}-[UID] cookies. The number on the end is your individual user ID from the users database table. This is used to customize your view of admin interface, and possibly also the main site interface." When in doubt, check the Codex first.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 8, "tags": "authentication, cookies" }
Publishing Remotely To Wordpress? Hey i know that there are options to post to a wordpress blog remotely by email or by another source. My blog is self hosted. What other ways is there to publish besides via email.
Built in to the current version of Wordpress there is "Remote Publishing" settings for Atom or XML-RPC, but that is geared towards programs that help you blog outside of your Wordpress control panel. You can configure it in the Settings > Writing area of your site's Wordpress dashboard. If you want to publish the content of an RSS feed to your Wordpress site, you will need a "re-feeding" plugin such as FeedWordPress: < Maybe you were thinking of publishing remotely as in a mobile app? Email is still probably the best route, but there are probably blogging apps, and they might need the Atom / XML-RPC setup to work with your site.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "remote" }
deleting terms programmatically I already checked out this page; < It does not say what happens to the posts that may have been associated with this action. Hence my question; So, what happens to them?
You can use below to assign all posts to another term during deletion mentioned on same page.. "The $args 'force_default' will force the term supplied as default to be assigned even if the object was not going to be termless." Other wise if there was only one term attached with post, post becomes term less.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, taxonomy, terms" }
Can I customize the To Email address on Contact Form 7? I want the email to be sent to different email addresses based on a drop-down Subject value. Can I do this with Contact Form 7?
Use Pipes. See the FAQ: < I.e.: [select your-recipient "CEO|[email protected]" "Sales|[email protected]" "Support|[email protected]"]
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "plugin contact form 7" }
Wordpress upgrade from 2.7 to 3.3 Permalink problem I have upgraded my wordpress from 2.7 to 3.3. Now if I try to change my Permalink /%category%/%postname%/ my home page is loading. However, all my pages are getting 404 page. I dont know how to fix the problem... I got no log.. Then I changed the theme to default theme twenty eleven then also I faced the same issue. Then I installed a new WP 3.3 then installed put my theme alone.. now no menu is displayed.. I dont know what is the problem.. any help is greatly appreciated.. Thanks in advance..
The problem is because in wp_options table I had ./ for home (row id 37)variable. I replaced with ""(blank) now the issue fixed..
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks, themes, theme twenty eleven, upgrade" }
How to set different settings for a mobile theme? My desktop version of wordpress theme requires using a 'static' page as the start page as it has custom shortcodes etc. While this is good, when it comes to my mobile theme, sadly the 'static' page is being displayed and because its a different theme, the shortcodes are not being executed. Is there a way to tell a mobile theme to display 'blog posts' as the default page and not use a 'static page' as a starting page for the theme?
Just wrap you code up in a conditional: if ( $GLOBALS['is_iphone'] ) { // do funky stuff for mini screens } `global $is_iphone;` will trigger `TRUE` for all mobile devices incl. tablets. ## Edit for WP 3.4+ Now there's `wp_is_mobile()` to make checks for `User-Agent`. It's basically a wrapper for `$is_iphone` and does the same.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "themes, theme options, mobile" }
Archive template limiting to 4 entries? I have a category called "javascript" and it's limiting my list to only 4 entries? <?php get_header(); ?> <div class="container"> <div class="row"> <div class="decorate"> <h1>Javascript</h1> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php endwhile; ?> <?php endif; ?> </div><!-- end decorate --> </div><!-- end row --> <?php get_footer(); ?> The link to this page is: <li><a href="<?php bloginfo('wpurl'); ?>/category/javascript">Javascript</a></li>
This has nothing to do with the loop in the template file. Check Settings>>Reading>>"Blog pages show at most..." That setting is the default setting for Archives, too, as well as Search results, etc. Use WordPress › Custom Post Limits « WordPress Plugins to vary posts limits in categories, archives, etc.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "templates, archives" }
Single-page wordpress theme navigation I'm trying to build single-page theme. I want user to navigate thru menu with anchors (for example `<a href="#About">About</a>`). I've extended Walker for wp_list_pages so it outputs anchors instead of permalinks. How to bite it now? I thought I will use `query_posts` for `'post_type' => 'page'` and just style those pages but is there more flexible way of doing this? Also this query displays all pages (all I want is just depth = 1) and I don't know how to order them same way as wp_list_pages does. Maybe there is some text to read about this kind of pages on the internet?
I've done a few templates that essentially are on one page. I used this code as the starting block for all of them: <?php $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page','posts_per_page' => -1)); foreach ($all_wp_pages as $value){ $post = get_page($value); $slug = $post->post_name; $title = $post->post_title; $content = apply_filters('the_content', $post->post_content); }; ?> It basically gets every page, you can then use the variables to build the rendered markup. Then a small change to meet you're depth requirement I would use: `$all_wp_pages = $my_wp_query->query(array('post_type' => 'page','depth' => 1, 'posts_per_page' => -1));` And finally `'posts_per_page' => -1` gets everypage, not limited to the number set in 'Admin > Settings > Reading' Hope this helps.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query posts, homepage, wp list pages" }
Adding paging to get_posts() I'm trying to add paging to the query below. However, I can't seem to get the paging to work. It shows previous/next links, however, they always show the same 2 posts. There are 8 posts in this query. //$paged = get_query_var( 'page' ); wp_reset_query(); global $post; $args = array('posts_per_page' => 2,'paged'=>1); $posts = get_posts($args);
If you make `paged` equal to `get_query_var( 'paged' )` that should do the trick. You may need to do something like `$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;` and then set `paged` to `$paged`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pagination, get posts" }
Get the post_id of a new post There are several ways to get the id of a post after it has been saved (auto, etc.), but is there a way to get the post id immediately after you create a new post? I am trying to create a directory using the post id, but I cannot seem to get a static post id. the code below seems to work but I get an auto incremented id back every time the new post auto saves the draft, I continually get a new number. function myfunction( $id ) { if (!file_exists("/www/foo/blog/wp-content/uploads/" . $id)) { mkdir("/www/foo/blog/wp-content/uploads/" . $id, 0777); } } add_action('save_post', 'myfunction'); I would like to get the post id that it will be saved as. Surely WP has a method for determining this correct? Or does the draft auto save every minute incrementing the id by one until the actual 'publish' button is clicked? thoughts? cheers! bo
Try this... add_action('post_updated', 'myfunction'); function myfunction( $post_id ) { global $post; if (!file_exists("/www/foo/blog/wp-content/uploads/" . $post_id)) { mkdir("/www/foo/blog/wp-content/uploads/" . $post_id, 0777); } } **NOTE:** Change from `save_posts` to `post_updated` which will stop the duplicate issue as it fires on **"publish"** only and not every time you hit `add new` or `update` etc. **NOTE:** I verified this for you by testing the snippet above - all good. **NOTE:** You can also use `(wp_upload_dir() . $post_id, 0777)` if you want a path that is more transportable or if you are developing a plugin or theme for public use.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 2, "tags": "posts, actions, save post, id" }
Is it possible to retrieve a post and its metadata at the same time? I usually use two steps to retreive a list of posts and the associated metadata: call get_posts(or a custom WP_Query), and then loop through each post returned and retrieve each posts metadata one by one. Is there any way to combine this into a single query? I guess I'm looking for something like a get_posts_with_meta() function?
Not worth it as it would be a convoluted query and work against most of the wp caching solutions.
stackexchange-wordpress
{ "answer_score": -3, "question_score": 1, "tags": "post meta, get posts" }
What is the difference between terms and tags? I am working on a problem to get the most recently used tags within the last 30 days. My current thought process is not working, so I am trying to come up with an alternative method. I came across get_term and get_terms, thinking they may be a way to an actual functioning solution to my problem. However, searching for "What is the difference between terms and tags in WordPress" is too general and I cannot find an answer. What is the difference between tags and terms? It what situations would get_term or get_terms be used? Thanks.
Simple yet tough question, taxonomies are just groups of categories, while terms are just single categories within these groups.* So, for example, if you create a new post and choose category for it - the category itself is a term, and opening `YourWordpressURL/wp-admin/edit-tags.php?taxonomy=category` you're going to see all the categories (taxonomy). Terms and Tags are similar at first glance, they just work differently: < < *this is possibly sometimes not true, as terms don't have to be categories, but I hate word "terms", it just confuses me, categories fits better
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "tags, terms" }
Passing variables to templates (alternatives to globalizing variables) I want to make my WP code simpler (there's some mess within header.php, page.php etc.). So, for example, I want to set something like this global: $foo = get_option('foo'); So `$foo` will work properly used anywhere in page.php, header.php, footer.php, loop.php and also within different theme files linked to functions.php (require_once). I already know two ways of achieving this, both require editing functions.php: ## Global dynamic function function foo() { return 'bar'; } ## Global constant define('FOO_BAR', 'directory'); Do I really need to fire a function in multiple places just for one variable? Isn't it an overkill?
You could also use this function: set_query_var('foo', $foo); WP will extract and expose all query variables in every template it loads, so you will be able to access it as `$foo`
stackexchange-wordpress
{ "answer_score": 10, "question_score": 3, "tags": "functions, templates, globals" }
How to store functions in... functions.php? I want to do some (sometimes really complex) stuff on my pages based on pages/posts IDs', Settings API, etc. Now I've all my functions written directly within page.php file, but I don't want it to leave it this way - it's really messy and it's hard to control everything. I'd love to have separate files for each function and load them from there. But there's a huge issue: functions.php function test() { return $post->ID; //or echo $post->ID; } page.php <?php test(); ?> Of course test() returns nothing. Is there any way to overcome that, or my approach is stupid once again? If yes - how should I store my functions outside of core theme files?
Globals aren't passed into functions. You have to declare them. Change this: function test() { return $post->ID; //or echo $post->ID; } ...to this: function test() { global $post; return $post->ID; //or echo $post->ID; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "theme development, functions" }
The purpose of the post_date_gmt? Why do we have 2 date fields in the `wp_posts`? What's the purpose of the `post_date_gmt`? When does storing the Greenwich time get handy?
Some countries use a Daylight Saving Time (DST): > Typically clocks are adjusted forward one hour near the start of spring and are adjusted backward in autumn. Sometimes there is no 2 am. Sometimes you get 2 am two times. To avoid cron jobs running twice or not at all WP needs the GMT (or more precise: UTC). UNIX time stamps cannot be used because they start in 1970 … and there is still the Year 2038 problem. If you want to write an imaginary diary of Gaius Julius Caesar or James T. Kirk … you will run into problems with the current system too, but they _may be_ solvable at least. :)
stackexchange-wordpress
{ "answer_score": 12, "question_score": 9, "tags": "date" }
Switching theme only changes style sheet being used I have a plugin that I'm using to switch themes for a specific user for development. When logged in as that user they see the different style sheet but the themes files, function.php, header.php, etc are the active theme for everyone else. What I am doing wrong? function change_user_theme($template) { global $user_ID; if ( in_array( $user_ID, array( 5 ) ) ) { $template = 'fezmobile'; } else { $template = 'fezforprez'; } return $template; } add_filter('template', 'change_user_theme'); add_filter('stylesheet', 'change_user_theme'); add_filter('option_template', 'change_user_theme'); add_filter('option_stylesheet', 'change_user_theme');
Take a look at my answer here: Switch Theme Through Options Panel The code is as follows: add_action( 'setup_theme', 'switch_user_theme' ); function switch_user_theme() { if ( in_array( wp_get_current_user()->ID, array( 5 ) ) ) { $user_theme = 'fezforprez'; add_filter( 'template', create_function( '$t', 'return "' . $user_theme . '";' ) ); add_filter( 'stylesheet', create_function( '$s', 'return "' . $user_theme . '";' ) ); } } You have to swap the template and stylesheet on the `setup_theme` action.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development" }
Using default wordcount javascript in Wordpress on custom wp_editor() areas I have two `wp_editor()` instances on pages and posts used to populate the sidebars of my three-column website. I would like to use the default wordpress word-count script on the two wp-editor areas to get the word-count of the content within them. I enqueued the script and added the required HTML but the wordcount was always that of the main content editor area. Has anyone managed to use this functionality with custom wp_editor areas and what HTML will I use? I have searched on the web but could not find any examples where the default script is used. Thanks in advance nav
Git this to work by using the following line of code in my theme's functions.php. $wordcount = str_word_count( strip_tags( $content ), 0 ); I got this piece of code from a stackoverflow post. The only disadvantage with this code is that it does not update dynamically which is not a big issue as the current wordcount will show up every time the post is updated. The problem with using javascript on which event I should trigger the wordpress function on. WordPress's wordcount functionality is tightly coupled with the default editor and I had to duplicate their javascript to try and get similar functionality which is not a good choice. I would still like to get some thoughts on this by a more experienced WP developer. Thank you. nav
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp editor" }
LESS compiler for Wordpress can I compile some .less-files automatically by using Wordpress. I found just lessphp Thanks Ogni
Alternative see the lessphp Project: < Works fine and hase an team of contributor. But has not an out of the box function for WordPress; but uts only PHP and the WP has the right Hooks. Do you will only use in themes, then its also fine, that you include this and it works with your requirements and no dependencies to an plugin. For an easy use in WP, see this project < its an wrapper and use lessphp; but an new dependencies. But its better as an plugin, if the customer change the plugin with updates and other doings, and easy to use.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php" }
difference between add_options and register_setting I am confused. Want to save data for my plugin. There are people who use add_options and there are others who use register_settings. My question is What is difference between `add_options` and `register_setting`?
register_setting() uses Settings API, which is just an API for options.php, is easier to use, more secure and preffered way of storing options since WordPress 2.7. If you need to store only a few options or doing simple plugin just for yourself - it's really up to you which one to use :) Here's the Settings API (well) explained: < Basically it makes a few things much easier, you don't have to render whole forms all over again (great for plugins/themes with many options), you don't need to care about nonces etc. So, to sum up, both these functions actually do the same thing :)
stackexchange-wordpress
{ "answer_score": 10, "question_score": 8, "tags": "plugins" }
Display a custom taxonomy as a dropdown on the edit posts page When you create a custom taxonomy, seemingly the only options are to display it as a tag (non-hierarchical) or category (hierarchical). Is there a way to display them as a dropdown menu? I realise that this an be done using `add_meta_box()` and actually manually adding it, but I'm looking for a builtin way (if one exists), to save lots of code! Thanks.
Unfortunately there is no way of doing this with `wp_register_taxonomy()`. When you register a taxonomy, the default metabox is either checkboxes (hierarchical) or as a cloud (non-hierarchical). The only way round it is to de-register the existing metabox and add a new-one in its place. By carefully mimicking the 'default' metabox - you won't have to process the data yourself, but let WordPress automatically handle adding / removing terms. The details of how to do this are given in this answer. You may also find this GitHub repository helpful (which now includes the ability of creating terms on the fly in the new metabox). The linked resources refer to creating a metabox with radio boxes, but it could be easily adapted for drop-down menus.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom taxonomy, dropdown" }
Images get uploaded itself from the computer I have a lot of images in my computer and I want to upload them to my website. For that I am looking for some automated plugin in which I can copy those images and it would upload them itself. Is there any Wordpress plugin that does it? ## EDIT To clearify what I want to achieve is, **When I drag and drop images to the FTP in a folder, all of those images get posted itself.** Thanks in advance.
This plugin does a batch upload and creates a new post/page/cpt from each file Fuxy's WP Images 2 Posts You would only achieve the " _Images get uploaded itself from the computer_ " if you make a custom script (Automator in Macs, don't know in Windows...) that would run in your OS and do that for you... But, I don't have any suggestion for the "auto upload" trick, neither on how to connect that with a plugin... seems quite an ultra advanced task...
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, images" }
jquery document ready function not being called For some reason I can't get the jquery document ready to fire for my plugin my javascript jquery(document).ready(function($) { alert("hello world"); $("#testdiv").text("hi"); }); the source from my website <link rel='stylesheet' id='admin-bar-css' href=' type='text/css' media='all' /> <script type='text/javascript' src=' <script type='text/javascript'> /* <![CDATA[ */ var fantasy_golf = {"ajaxurl":"http:\/\/example.com\/wp-admin\/admin-ajax.php"}; /* ]]> */ </script> <script type='text/javascript' src=' <script type='text/javascript' src=' when I follow the source of my fantasy-golf.js (in firefox's source) it has the correct version of my js. (it shouldn't be due to it caching an older version)
Try using `jQuery` instead of `jquery`. (Note the capital "Q".) Edit: Upon viewing your source, you have an extra `});`. Working example
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugin development, jquery" }
Image Upload from URL I really like the way SE uploads an image from a URL (I'm sure many do!). I've been searching, but can't find, **is there a plugin or a method similar to this available for WordPress?** I know an image can be uploaded and crunched directly from a URL by entering the image URL into the File Name box after you click Upload/Insert Media >> From Computer >> Choose File !enter image description here This is a great feature, but not very widely known (I actually just discovered it). I would like something a little more like SE, where there is an option that let the user know to add the image URL. How can I go about adding simply the upload file field to a new tab in the media uploader? Here is a tutorial for How to add a new tab in Media Upload page in wordpress, but I want to add only some text and the file upload field to that tab. Any ideas? I couldn't find anything in the WordPress Codex that deals with this feature or the file upload field directly. Thanks.
WordPress Plugin Directory - Grab & Save > This plugin allow you to grab image from remote url and save into your own wordpress media library. By doing so, you never worried if the remote image was removed by its owner. This also save you steps to download the image to local computer and upload again to your own wordpress. > > After grabbing the image, wordpress will prompt you either to "insert into post" or "change attributes" just like after you upload an image.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 24, "tags": "images, uploads" }
Is there a PressThis that doesn't hotlink? What are some plugins or alternatives to the PressThis function? I want to use the PressThis bookmarklet to quickly blog about what I see online, but every time I do and include an image, it hotlinks to the image from the site I'm blogging about. That's bad, because I don't want to tax the site I'm writing about. I don't want to use a full-sized image. And I don't want the image to be broken on my site if the site I'm writing about to goes down.
PressThis bookmarklet does upload images to the wp uploads folder that you add to the article. Basically in the PressThis window go to the 'Add' menu and click on 'Insert an Image' icon. It will populate thumbnails of images found on the web page you are on. Click on the image you want to include in your post and that will open up a small window with the image you selected. As well there's an empty Description field and just above that field - on the right click on 'Insert Image' and it will insert it in your post. Now this will insert the image AND wrap a hyperlink to it to the web page that you got it from but once saved it will upload that image to your site.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, blog" }
Mass Mail Plugin to Email Specified User Roles I'm not looking to spam anyone, but I am looking for a mass mail plugin so I can select the User Roles (whether core or custom) by check box or comma separated entries of the roles, then type my message and send. The reason: I have a multi-author website with active contributors, authors and editors. I am looking for a simple way to email these groups. I don't care if it is a free or premium plugin. # UPDATE I tried the solution provided below, Emu2 - Email Users 2, but after using it for a few days, I found there is a conflict with the WordPress media uploader, causing http errors on upload with the new WordPress uploader and timeouts using the classic WordPress uploader.
WordPress Plugin Directory - Email Users > A plugin for wordpress which allows you to send an email to the registered blog users. Users can send personal emails to each other. Power users can email groups of users and even notify group of users of posts. I also use the Admin Menu Editor plugin to hide Email Users from lower level user roles.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, email, plugin recommendation" }
How to limit the number of posts on the home page? I am working on my first WP site and am having some difficulty. In my theme's index.php page, I see the following code: <?php query_posts(array( 'category__not_in' => array($headline), 'post__not_in' => $postnotin, 'paged' => $paged, 'numberposts' => 5 )); if ( have_posts() ): $postCount = 0; ?> <?php while ( have_posts() ) : the_post(); $postCount++;?> [more code....] So - you see I'm trying to limit the number of posts on the home page to 5, which I thought was the default. Anyways, it is showing more than 5 and I can't seem to get it to work. I've tried "posts_per_page" without luck. If my theme is overwriting it, any ideas where that may be? FWIW, I'm using the initiator theme by colorlabs Thanks!!!
here's what I ended up doing: <?php query_posts(array( 'category__not_in' => array($headline), 'post__not_in' => $postnotin, 'paged' => $paged, 'posts_per_page' => 5 )); if ( have_posts() ): $postCount = 0; ?> <?php while ( have_posts() ) : the_post(); $postCount++; if ($postCount < 6) { ?> [all my code] <?php } #end if ?> <?php endwhile;?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query posts" }
How to implement two separate featured images for each post/page So I would like to set two separate feature images for each post/page. One would be a rectangle for use in a slider and another would be a square for use on archive pages, search pages, category pages. WordPress can do this, but it either resizes the initial image to the nearest resolution or crops it. I would rather create it myself and upload it.
This plugin is what you're searching for...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, customization" }
Get Current Custom Taxonomy ID by Post ID If I know the current post id that i have in the variable $pid I use `$terms = get_the_terms($pid, 'custom_category');` How do I get just the `term id/term_taxonomy_id` if I `var_dump` `$terms` I see what I want...but I have no idea how the heck to return just the id, not an array, just the id. Bare in mind...I less than 1/2 know what I'm doing...just face rolling keyboard to get what I want...but learning more everyday.
(Probably better to use `get_the_terms`). $terms = wp_get_object_terms( $pid, 'custom_category', array('fields'=>'ids')); Get an array of term ids (will always been array, even if it is an array of one): $ids = wp_list_pluck( $terms, 'term_id' ); If you just want one id... then 'pop' out the last id: $id = array_pop($ids); See also PHP docs on `array_pop` here
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "custom taxonomy, taxonomy, terms" }
How to display only logged in user's post comments in comments area I am making a custom Wordpress site where School students logged in and add their posts. I am giving them rights to use wp-admin panel with little customization and modification. **_QUESTION:_** "How can logged in user be able to see comments of his own post only in edit comment admin panel" please suggest me some solution i am in need for the same Thanks in advance
i had been looking for the code where logged in users will be able to see post of his own only i have managed to make simple function that we can use for the same the function snippet has to be included in functions .php file in the theme folder which you are using function my_plugin_get_comment_list_by_user($clauses) { if (is_admin()) { global $user_ID, $wpdb; $clauses['join'] = ", wp_posts"; $clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID"; }; return $clauses; } // Ensure that editors and admins can moderate all comments if(!current_user_can('edit_others_posts')) { add_filter('comments_clauses', 'my_plugin_get_comment_list_by_user'); } Thanks NIkhil Joshi
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "admin, comments, wp admin, users, user access" }
can't upgrade wordpress or install plugins, it seems to "think" it's still on a local installation I'm pretty new to Wordpress, so sorry if this is an obvious mistake :) I've just moved a site from local installation on my computer to a live server. When I'm trying to install plugins or upgrade the Wordpress vs, I get this error message: > Could not open handle for fopen() to C:\Websites\Danabick-shanuniCoIL\site/wp-content/wordpress-3.tmp It seems it still "thinks" it's a local installation. I'm guessing I missed something when moving it, but not sure what. Any help would be appreciated :) edit: i tried searching the database for the problematic string, it's not there. if not the db, where can it be coming from?
So, after I couldn't find the string in the db or the files, I looked at it again closely, and the path looked similar to what I have on the server. I guessed the c:/ wasn't referring to the local installation I had, but to the location on the server. Talked to the hosting company, and apparently it was a permissions issue... (- _facepalm_ -) Problem solved :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "database, configuration" }
Wordpress settings API VS Table In Database? I have created an options page for my plugin using Settings API. Now I want to create another tab where user will create records. He will also like to delete/edit records. There will be 10-20 records only. I want to stick with settings API for these records (Single field in database) but I am at a lose to decide if it is possible with settings API. If yes, can you guide me how as user will like to edit/delete records as well. Or should i opt for a table in database?
You should use Custom Post Types. No extra table, no missuse of Settings API. Use CPTs with Title field, WYSIWYG/textarea (for caption) & a featured image (for the actual slider image). This way later themes can also make use of it. Just name the CPT "slider". Here´s a read why sliders & carousels are not a good choice.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "settings api" }
How to allow only certain users to login I have looked but could not find either a plugin or code that allows only certin users to login in to my wordpress site e.g wan, velma, bob and no other. Does anyone know how to do this. Thanks Tim
What you can do is to set your specific list of users to admin, and use Theme my Login to redirect admin users to the page you want to see, and to set all other roles to redirect to an invalid page which they can't have access.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "login" }
How do i know which action / filters are called when i call get_option() I need to know which action / filters are called when i do a `get_option()` call, how can i do that?
Go down the rabbit hole... <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "actions, options" }
Query specific posts from parent by slug rather ID I'm developing a theme in a local machine and migrating it to a production server. To keep things in sync, i'm trying to avoid any queries of specific ID's On the homepage, i'm trying to query the top 3 pages (by menu_order) from a parent page (NOT the homepage). It works perfectly with the hardcoded ID, but i'm stumped trying to figure out a way to do this without the ID. Seems like I should be able to use the slug, but I can't figure it out. Here's the code i'm working with: $args = array( 'post_type' => 'page', 'posts_per_page' => 3, 'post_parent' => '74', 'orderby' => 'menu_order', ); query_posts($args); So rather than 'post_parent' => '74' I want to use the page slug (e.g. 'books'). Any ideas? This question seems promising, but as others commented, I'd also like to avoid direct DB queries and the second suggestion didn't work working.
there are two WordPress functions you could try: < (as suggested by @t31os in the comments to your quoted link) < if you have already tried them, please describe how these failed to do what you want.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query posts, slug, id" }
Conditional tag I am using this code to show custom code on single posts. function post_footer() { if (is_single()) { ?> <div class="custom"> <h1><a href="<?php the_field('live_demo'); ?>" target="_blank">Live Demo of <?php the_title(); ?><h1> <h1><a href="<?php the_field('download'); ?>" target="_blank">Download<h1> </div> <?php }} How to edit so div should appear only on single post of specified categories, not on all posts.
If it is a single page: `is_single()` returns `TRUE`. If a `$post` is in a specific category: `in_category( $cat )` returns `TRUE`. It needs `$cat` as ID, name or (string) slug. Anyway: Searching for a list of conditional tags isn´t that hard.
stackexchange-wordpress
{ "answer_score": 3, "question_score": -2, "tags": "customization" }
How to create a list of links to post with specific category I'm trying to create a list of links to post that are tagged a specific category. Is this possible? I'm not even sure where to begin. Any help? so, for example I'm trying to show the 1st ten post that are tagged "video". thanks,
You can do this by putting this where you want to display the list : <ul> <?php global $post; $args = array( 'numberposts' => 10, 'offset'=> 1, 'category' => 1 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> In here all you need to do is replace the category ID with your desired categ ID. `'category' => 1 and that's all
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, categories" }
Getting trackback spam, even with trackbacks disabled I'm having a heck of a time having trackbacks being disabled period on my self-hosted blog. I've disabled the "Allow link notifications from other blogs (pingbacks and trackbacks)" option, and have all comments going through disqus, yet for some reason I'm getting 20-50 trackbacks a day to the blog directly (not through disqus). Is there something obvious that I'm missing?
If you are using a twentyten/eleven theme, they hardcode the pingback meta tag into the `head.php` file. Remove that line or use your own theme. Also, and maybe it's only in multisite, but the X-Pingback header is sent along with the xmlrpc endpoint url as well. Removed with the following: /** * Remove the X-Pingback header, since pingbacks are disabled */ add_filter('wp_headers', 'custom_remove_xmlrpc_header', 1, 2); function custom_remove_xmlrpc_header($headers, $wp_object){ if (array_key_exists('X-Pingback', $headers)) unset($headers['X-Pingback']); return $headers; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "spam, configuration" }