INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Custom Post Type Archives by Year & Month? How do you display the archives of a Custom Post Type by Year & Month?
Yes, you can. All you need is make a filter for `wp_get_archives();` so it accepts `post_type` parameter: function my_custom_post_type_archive_where($where,$args){ $post_type = isset($args['post_type']) ? $args['post_type'] : 'post'; $where = "WHERE post_type = '$post_type' AND post_status = 'publish'"; return $where; } then call this: add_filter( 'getarchives_where','my_custom_post_type_archive_where',10,2); Whenever you want to display archive by custom post type, just pass the post_type args: $args = array( 'post_type' => 'your_custom_post_type', 'type' => 'monthly', 'echo' => 0 ); echo '<ul>'.wp_get_archives($args).'</ul>';
stackexchange-wordpress
{ "answer_score": 17, "question_score": 17, "tags": "custom post types, archives, date, custom post type archives, wp get archives" }
get_category_link() is returning nothing <?php $categories=get_categories('taxonomy=galeriak'); foreach ($categories as $category) { ?> <li><a href="<?php echo get_category_link( $category->term_id ) ?>" title="<?php echo $category->name ?>"><?php the_term_thumbnail ( $category->term_id, $category->taxonomy, $size = 'thumbnail', $attr = '') ?><span><?php echo $category->name ?></span></a></li> <?php } ?> I use this code to display the categories from the "galeriak" taxonomy. Everything is working, except the href part, its return nothing. I tried it with and without the echo, but nothing seems to work. Any ideas?
You should be using `get_term_link` instead, also for consistencys sake and to future proof, use `get_terms` instead of `get_categories`. Both work on categories/tags and all custom taxonomies. Also check for the return of a WP_Error object ( returned when an invalid or nonexistent term is passed )
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "links, categories" }
wp_list_pages Format only on Recently Modified Pages wp_list_pages can be a great tool for displaying a tree structure. You can specify the depth, child of, and show_date of when the page was last modified. However, if I want to only show the date for pages that were modified in the last...24 hours say...How can I specify this?
By default the function cannot do this, but you can specify a custom walker when you call the function, and then implement your own walker: < < This way you can keep the code the same, but add a check on the date of the page being walked over, and 'skip' it if it doesn't match your requirements ( or add other desirable markup etc ). more: < < < <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp list pages" }
Creating a blog on my companies new website using Wordpress but I have sidebar issues As said in the title, I am creating a blog on my companies new website using Wordpress but I have sidebar issues. The website is only in production phase at the moment. The Link is so you can see is: < Heres an image of what it is currently. !enter image description here Whenever I try to move the sidebar up it messes up and the bit move up dissapears. Heres another image to show you what I mean: !enter image description here I hope the images help explain what I am trying to say. Im really stuck on this so I hope someone can help.
You need to do three things: * firstly, your markup is incorrect, take the container_24 div the main content sits in and make it grid_17 so it doesn't take up the entire width of the container div. * The sidebar needs to go in the container div along with the content, else it will be pushed downwards by the container div * Because of the above issues, you've introduced numerous negative and left-hand margins. If you remove these margins and do the above, you should have a vast improvement. remember where grid systems are concerned you have a container div, which contains all the columns, and the columns all add up to the full width of that container.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, css, sidebar, front end, blog" }
Custom post type permalink structure I've browsed tons of Q/A on stackexchange, google, wordpress forums... but haven't found yet a definitive answer to what looks like to be a common issue since the introduction of custom post types. I've set my permalinks structure from Wordpress admin permalink settings page as: /%post_id%/%post_name%/ since this is a good practice to improve database performance however, I noticed my custom post types (I have several in one configuration) still appear as: %cpt_slug%/%post_name%/ while what I really want is %cpt_slug%/%post_id%/%post_name%/ and actually would love if it could also work as %cpt_slug%/%post_id%/%taxonomy%/%post_name%/ but as for now, I would like to get the post_id work in the cpt structure how to achieve this? there was a wordpress plugin but apparently it was withdrawn because had some issues (and anyway is no longer mantained)
function myrules(){ add_rewrite_rule('^yourcptslughere/([^/]*)/([^/]*)/([^/]*)/?','index.php?p=$matches[1]&taxonomy=$matches[2]&name=$matches[3]','top'); } add_action('init','myrules'); Replace the ' **yourcptslughere** ' with what you wanted, and then add that to functions.php then flush your rewrite rules, and the final example you posted should work. I doubt it will be what `the_permalink()` returns however so you will have to construct the urls yourself, however they should be viewable at those URLs **e.g.:** example.com/randomcptslug/123/exampletaxonomy/testpost
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, permalinks, url rewriting, rewrite rules" }
get post id using the $query_vars variable How can I get the ID of a post (or page) based on the $query_vars variable? I want to do something like $query_vars['post_id'] But I don't have a reference page that has the list of $query_vars perams. The code will be using the template_redirect action hook.
When viewing a single post, `get_the_ID();` used within the loop will return the current post's ID. > But I don't have a reference page that has the list of $query_vars params... Dumping it global $wp_query; var_dump($wp_query->query_vars); would provide such a reference. Where you'd subsequently see that `$wp_query->query_vars['page_id']` yields the page ID.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "query" }
strtolower <title> Currently the WordPress Twenty something themes all have this as the title: <title><?php global $page, $paged; wp_title('~', true, 'right'); bloginfo('name'); $site_description = get_bloginfo('description', 'display'); if ($site_description && (is_home() || is_front_page())) echo " ~ $site_description"; if ($paged >= 2 || $page >= 2) echo ' ~ ' . sprintf(__('Page %s', 'schema'), max($paged, $page)); ?></title> Would it be possible to have the whole bit returning as lowercase perhaps?
Wrapping everything in strtolower should work: <title><?php global $page, $paged; echo strtolower(wp_title( '|', false, 'right' )); echo strtolower(get_bloginfo( 'name' )); $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) echo strtolower(" | $site_description"); if ( $paged >= 2 || $page >= 2 ) echo strtolower(' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) )); ?></title>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "title" }
Display posts between two particular dates I have this code for display posts between two particular dates: $s = '2011-10-23'; $e = '2011-11-17'; function filter_where($where = '') { $where .= ' AND post_date >= $s AND post_date <= $e'; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); But that's not work until change to this: function filter_where($where = '') { $where .= ' AND post_date >= '2011-10-23' AND post_date <= '2011-11-17''; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); What's wrong in first code?
I think its because the SQL statement needs the dates inside the quotation marks. Try $where .= " AND post_date >= '$s' AND post_date <= '$e'"; That should work, otherwise, try $where .= " AND post_date >= '".$s."' AND post_date <= '".$e."'";
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query" }
Cancel comment filter? Is it possible to cancel comment submission if certain creteria are met? I want to limit the number of characters in a comment. Where do I test the length and cancel the comment if it's over a given length? Would the pre_comment_approved filter do this? And does anyone have some sample code for how to use pre_comment_approved ? Thanks
You are certainly on the right track. You can create a plugin (create a directory in "wp-content/plugins" and create a php file with the same name as the folder) with the following code: function wpse_33944_filter_handler( $approved , $commentdata ){ if(strlen($commentdata[comment_content]) > 5) { return false; } return true; } add_filter( 'pre_comment_approved' , 'wpse_33944_filter_handler' , '99', 2 );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "comments" }
How do I escape a ']' in a short code? How do I escape a right bracket in a short code? I'm working on a Google Map plugin that has encoded points. Sometimes the polygons have the ] in it, which makes WP think that it's the end of the shortcode. For example: [my_shortcode latitude='36.93' longitude='-72.98' encoded_points='ortlF~g]tM?cZEH`z]}|@DQfi]' ] I've tried `&#93;` which is isn't causing a problem for WP, but it is causing a problem for my Google map code. I could use Regex to replace ], but maybe there is a simpler way. Does shortcode have an escape character?
I don't know of an official escape syntax for shortcodes and there likely isn't one. When wordpress parses for shortcodes it looks for _[_ and _]_. If you want to use square brackets within a shortcode, using the respective html ASCII entities escapes them. I.e. replacing _[_ by `&#91;` and _]_ by `&#93;`. Wordpress will not recognize `&#93;` as the end of the shortcode. Whether that serves your purpose obviously depends on whether it gets converted to _]_ before being passed to the Google Maps API or whether the API handles it as expected. I have no experience with that, so can't say.
stackexchange-wordpress
{ "answer_score": 21, "question_score": 20, "tags": "shortcode" }
Plugin for wikipedia style references in WP? I find inline links offputting to read so want to use wikipedia style foot-of-article references with incremental numeric linking to the external link reference. I can just stick the HTML in but on the off chance is there any plugins on WP for semi-automating the process?
I think Netblog plugin seems to be what you're looking for. > Connect posts and external resources (websites, pdf, doc, zip, exe). Use Captions, Footnotes, Bibliography. Netblog is highly customizable.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "links, wiki, references" }
Are href attributes of a elements filtered on output to add the current path? I have some code that basically looks like this (it's more complicated, but even this example shows what I'm running into): echo '<a href="#">TEST</a>'; However, what gets sent to the browser is not `<a href="#">TEST</a>`, but instead `<a href=" Is WordPress filtering this somehow to prepend the current page URL in front of the `#`? It just occurred to me that this code is called by a shortcode, which I imagine opens up the possibility of it being filtered somehow...
Just ran that exact code snippet on WP 3.3 to test. In practice, `<a href="#">test</a>` is rendered in the markup correctly, but the browser will attempt to navigate to ` when you hover over the link or click on it. This is the expected behavior of a link like this ... so unless you have other code on the page that's actively changing the links, this is what I'd expect to see. Tested under both Chrome and IE just to make sure I wasn't crazy.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "filters, urls" }
Change Wordpress.org hosted plugin readme.txt is it possible to change the readme.txt of a plugin that is hosted at ` without tagging a new version? I would like wordpress.org to show the new readme.txt. I have added a link to the plugin documentation but I do not want to force the users of updating their version because of this change.
Yes, just change the readme in the tagged directory that is marked as stable.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "plugin development, wordpress.org" }
Can't change permalink url after hitting 'ok' and 'update' I am trying to change some of the titles of my posts and their respective permalinks. After I edit the title and permalink and click 'ok', the permalink appears to have changed temporarily. However, when I click 'update', the permalink changes back to what it was originally. Is there anything that may be preventing the change that I might have overlooked?
Have you somehow hidden/removed the slug metabox? (is something like this located in your functions.php?) function remove_post_meta_box() { remove_meta_box('slugdiv', 'post', 'normal'); } add_action('admin_menu', 'remove_post_meta_box'); If that's the case, it's causing the error. There is a Trac ticket for this already, but the only way to currently solve it is to remove it.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "permalinks" }
How to debug WordPress correctly? I'm using a few plugins and UpThemes framework on my new website and if I turn on Wp Debug I can see that there are a few errors related to Deprecated functions (but website is working). What I would like to know is if there is a plugin, a software or a pray (lol) that I can use to know exactly where the deprecated code is so I'll be able to use the new one. Which is the plugin/software that you use to debug your plugins, themes?
What you're looking for is the Log Deprecated Notices plugin. (Don't run it on a production site, as it is a direct-to-database log.) What it'll do is convert those cryptic messages that are likely to reference has_cap() or some line in functions.php, to what's actually going on. The Debug Bar plugin is also nice. It tracks notices of that pageload, using the conversion code from Log Deprecated Notices.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugin development, theme development, debug, wp debug, deprecation" }
How to fix the amount of comments displayed for each post? I've received an old wordpress 2.8 and successfully upgraded to WP3.2.1. I've just discovered that the amount of comments displayed in the WP Admin 's list of posts is wrong. Would you know how i could fix that by, perhaps, running a clever SQL update query in the database, that would fetch the real number of comments associated to a post and update the post row accordingly?
I nailed it: UPDATE wp_posts as p SET comment_count =(SELECT count(*) FROM `wp_comments` WHERE `comment_post_ID`=p.ID);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "mysql, comments" }
Multiple wp_localize_script Is it possible to localize a script more than once? I want to send two separate arrays of params. Or is it only possible to localize a script once, in which case, I'll have to combine the arrays? I'd like to do something like this: wp_localize_script('my-handle', 'my_object1', $data1 ); wp_localize_script('my-handle', 'my_object2', $data2 );
This will be possible in WP 3.3: <
stackexchange-wordpress
{ "answer_score": 7, "question_score": 7, "tags": "wp localize script" }
How code a redirect back to page from form thanks I building a site in WordPress (my own theme) that includes a very simple "sign up" email form. Person enters name and email address and hits submit button. Client currently using a script through Bluehost so I want to recreate vs. using a form plugin. The form is fine. After hitting "submit" person is redirected to a "Thank You" page. I would like to be able to add a "back to page" link after the "Thank You for signing up" message that would take them back to whatever page they were on (the form will be on most site pages). Tried adding this to the template: <?php $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "<a href='$url'>Back to Page</a>"; ?> but it generates an error message because it's kicking back to Bluehost, not to the original page. Can anyone help? Thanks!
There's a great function called wp_redirect(), unfortunately not supporting "last page" argument yet, but I hope it will soon. I believe the easiest (but not the most elegant way) way to achieve what you need is by using JavaScript, in jQuery it will look like: <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#back-link').click(function() { history.go(-1) }); }); </script> <a href="#" id="back-link">Go back</a> It won't refresh the last page though, but in my opinion it's even better. Hope it helps.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "redirect" }
restrict subscribers to admin area. They have their own profile on fron-end I want to make a simple website where users can register to my site. they can have their profile page. when they login they should be redirected to their profile page. Subscribers should not be allowed to view their profile in admin side. suggest me plugins or way to do it. Thanking for answer.
you don't need any plugin.just add this code to your function.php file which you will find in your theme folder. add_action( 'init', 'blockusers_init' ); function blockusers_init() { if ( is_admin() && current_user_can( 'subscriber' ) ) { wp_redirect( home_url() ); exit; } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
Displaying errors with settings api I'm not using the full settings api, just this code: register_setting( 'my_options', 'my_options', 'my_options_validate' ); Then my validation: $options = get_option('my_options'); if(error_found){ add_settings_error( 'my_options', 'settings_updated', 'error_message_here', 'error'); } return $options; But on postback no errors are displayed. So my questions are: does simply setting an error message result in its display? do I have to use the full settings api to have errors displayed? do I have do anything to disable the "settings updated" message on postback? I've tried using settings_errors but no errors show.
> does simply setting an error message result in its display? do I have to use the full settings api to have errors displayed? do I have do anything to disable the "settings updated" message on postback? You need to add a call to `settings_errors`, e.g.: /** * Displays all messages registered to 'your-settings-error-slug' */ function your_admin_notices_action() { settings_errors( 'your-settings-error-slug' ); } add_action( 'admin_notices', 'your_admin_notices_action' ); If you don't, then the errors you added will not be displayed. You may also want to check that `$error_found` is true. It is not a WP constant I recognise, so I assume it is part of your code ( and hasn't been set ) ( also, it's missing a `$` at the start? ). There is also the possibility that no errors have occurred, or that your validation is allowing invalid cases to pass through.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "settings api" }
How can I modify page <h2> content in the admin panel? I'm modifying the layout and content of the wordpress admin panel using a custom plugin. For most sections I have been able to change the page heading (i.e. the title wrapped in h2 tags at the top of each page), however I've been unable to do so for sections to relating post types, specifically adding and editing posts and pages. Currently when adding a new page to the wordpress site, the heading is 'Add New Page', but I'd like to be able to modify this text - so far I've been searching for the hook to do this but have been unable to find one.
In `wp-admin/edit.php` at line 189 you can see that the title text is grabbed from the labels of the post type: <h2><?php echo esc_html( $post_type_object->labels->name ); ?> ... </h2> When you register a new post type (`register_post_type`) you can also define its labels. The available labels are listed in the Codex.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, wp admin" }
User ability to favorite or 'like' content I have a few different custom content types and would like to give my users the ability to favorite or 'like' (like Facebook, but not for Facebook) pieces of content so that they can later view a list of their favorited content. I've searched everywhere but haven't come up with a clean solution. I'm pretty comfortable with SQL and PHP but want to make sure I'm doing this in the most efficient, clean way possible. Any ideas?
You might have already thought of this, but have you thought about a plugin. I was sure that the WPMU Dev guys did one that did a like (that wasn't FB related) but I can't find it (if you want to look it must be somewhere here but I've gone through it all and I can't find it now < I also found these plugins which might help: < (Unfortunately I've not had time to test them first, which I usually like to do before recommending stuff, but maybe they'll help you in any case) Cheers Nick
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "users" }
$post in wp_query? How do I get the $post Variable in a WP_Query started loop? I have to get the excerpt, raw $post->post_content and further things. This is why I have to get Access to the Variable itself. How am I able to do this? Thank you in advance!
$query = new WP_Query( $args ); while( $query->have_posts() ) { // this fills in the $post global with the next post from the query $query->the_post(); // we're now ina classic wordpress loop, and can use all the usual stuff the_title(); the_content(); echo $post->post_content; } // lets clean up after ourself so else we might mess up other queries and function calls wp_reset_postdata();
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, loop" }
Installing Google analytics to home page I've installed a plugin that puts google analytics code to the page of each post. But it did not install google analytics code to home page and because only a small portion of users click on the post's page I can not track the users. How can I install google analytics manually to the home page and if I do so I could not use the plug-in any more? My theme is Twenty Ten 1.2.
This depends on your theme. Most themes have a call the `wp_footer` hook at the bottom of every page - which means it's at the bottom of every single post, every single page, and the home page. Rather than editing all of your theme files to include your tracking code, use a plugin that ties in to `wp_footer` and adds the code there. There's actually a plugin that will do this _for_ you - which means you just install the plugin, no code editing is required. Google Analytics for WordPress I did test this exact plugin with a fresh install of Twenty Ten 1.2. It works just fine and displays the script on the home page. You must have another plugin interfering with the Google Analytics one or you've made changes to the theme that's preventing the plugin from working properly.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "homepage, google analytics" }
How to Catch Last Widget box From Same Widget Area? is there any Way to Catch Last widget box or div from same widget area?? i mean i have 4 widgets in footer widget area but due to design issue my 3rd widget box style+width is different.so i want to add extra class to 3rd box container using php.is there any way to do that? please reply. Thanks in advance. :)
Add the following code in your functions.php file of the theme directory. Replace widget name "Home Widget Area" with your widget's name /*=============WIDGETs CSS CLASS CONTROLLER==============*/ $GLOBALS['my_widget_num']=1; function edei_widget_class_adder($params){ if( $params[0]['name']=='Home Widget Area' ){ $GLOBALS['my_widget_num']++; if( ($GLOBALS['my_widget_num']%4)==0 ){ $params[0]['before_widget'] = str_replace('class="', 'class="marginAdjust ', $params[0]['before_widget']); } } //print_r($params); return $params; } add_filter('dynamic_sidebar_params','edei_widget_class_adder'); function edei_widget_counter_reset($sidebars_widgets) { $GLOBALS['my_widget_num'] = 1; return $sidebars_widgets; } add_filter('sidebars_widgets','edei_widget_counter_reset');
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets, sidebar" }
Most Flawless Way To Transfer from Dev to Prod > **Possible Duplicate:** > Easily Move a WordPress Install from Development to Production? So I've been working with WordPress for a while now and I usually develop locally and then upload everything to my Prod server... however, I've experienced a lot of differing results, especially when using plugins. I usually export the database, but things like the location of the domain don't always seem to get changed even after changing them within the WP admin beforehand. What's the best way to move from Dev to Prod and keeping everything intact? Then, what's the best way to move your site from a subdirectory on the same domain? Please don't point me in the direction of the WP docs... it's the first place I looked.
_Any_ difference between dev and prod is bad. Here is what I do: * Have a **different ip for dev server** (Whether internal, external, or on local computer is unimportant) -- but dev server must be the exact same setup (see bottom paragraph) * **Change the hosts file(see here)** (on yours or a testing computer or a virtual machine) to point to dev server ip * Result: HTTP requests sent to dev server have Host header field set as "example.com" **exactly like it will be for the prod server**. This method removes two differences often encountered otherwise: 1. having to change domain name 2. having dev code in a subdirectory, but prod code in root or diff subdirectory. This is because I use git to transfer files between dev and prod. . . The dev server is set up exactly the same as the prod server (see Chef or Puppet for how to programmatically manage servers).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "export, hosting, customization, production, migration" }
Accessing array elements (get_pages) I'm trying to access the page ID of the child so that I can recursively call the get_children function on that child (to get grandchildren). if ($CurrentPage) { $args = array( 'child_of' => $CurrentPage ); $children = get_pages( $args ); foreach ($children as $key => $value) { echo $key.'=>'.$value.'<br />'; } // End foreach. } // End IF. I actually get an error: **Catchable fatal error: Object of class stdClass could not be converted to string**
The return set of $children is an associative array. So you can get the IDs with: $children = get_children( $args ); foreach ($children as $k => $v) { echo $k; // do stuff with $v }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "array" }
Custom Post Meta on a Different Page? I'm using this code to call some custom post meta named port_excerpt: <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'port_excerpt', true); ?> This works like a dream when used on the template it is intended for: < But the custom post template I am using (as in 3.0 custom post templates) is being used for a portfolio, as a result I also need to call this on my portfolio page: < How do I call port_excerpt, which is meta contained within a custom post, on the portfolio page above?
You need to put this inside the loop running on the portfolio page. echo get_post_meta( get_the_ID(), 'port_excerpt', true );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom field" }
Accessing value from associative array Here's my code: $args = array( 'child_of' => $CurrentPage ); $children = get_pages( $args ); foreach ($children as $child) { foreach ($child as $key => $value) { echo $key['post_title']; } }; And output: IpppppppcppptpppppgmppcfIpppppppcppptpppppgmppcf The output appears to be the first character of the $key, repeated over both children. ID , post_author , post_date , post_date_gmt , post_content , post_title , etc.
You're doing one to many loops. What you want to be doing is this: $args = array( 'child_of' => $CurrentPage ); $children = get_pages( $args ); foreach ($children as $key => $value) { echo $key['post_title']; }; Or you could also: $args = array( 'child_of' => $CurrentPage ); $children = get_pages( $args ); foreach ($children as $child) { echo $child->post_title; }; It's entirely up to you, but since you already know what elements each `$child` has, why not stick to the same syntax as used in the `get_pages()` Codex article?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "array" }
Wordpress search results I have installed Job Manager and managed to filter the search to only display jobs (i.e. post_type = jobman_job) and it works ok however, when displaying the search results, it only shows the title - it does not pull the short description (the "excerpt") like the normal search does. Can anyone give me some direction on how to make the search display the job content?
used post_type to differentiate the specific Job Manager posts and search those
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, search, query" }
Modifying search results based on post_type Is there an easy way to highlight search results based on post_type? I am using Job Manager plugin and when a site search is performed, I want to simply add a note e.g. (Job) next to the Job Results.
i think you can PHP it using an if statement.. like so: **Say this is the loop.. (simple one i know):** <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $post_type = get_post_type_object( get_post_type($post) ); $post_type_name = $post_type->labels->singular_name if ($post_type_name == 'example') { echo '<div class="highlight searchResults">'; } else { echo '<div>'; ?> <h3><?php the_title(); ?></h3> <p><?php the_excerpt(); ?></p> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> . Dont forget to change the 'example' with the singular name of the custom post type you are checking for in the search restuls... Hope this helps :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, filters, search" }
Snippets: is it better to add them in functions.php or make site-specific plugins? Should "snippets" (short code or functions) be added to: 1. the theme's functions.php? OR 2. make site-specific plugins? Which is better from technical, security, performance, etc., standpoint? Besides the reason that during an upgrade the theme's functions.php may get overwritten, what would be the other reasons to make create site-specific plugins out of the "snippets?
From performance point of view, I don't think there is any difference between functions.php and plugins : it's just different places for the code to be. I would be practical : if the function is part of the theme's core (say, a scrollable slider in the header without which the theme is worthless) : it's a function of the theme. If it is a generic function that could be useful to another theme (say, custom data field), it's a better choice to make it a plugin, because you could easily copy/paste this function if the files are separated from the theme.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, functions, shortcode" }
Can I develop a social networking Site using WordPress and its Plugins? I am completly new to WordPress. I have a requirment where I need to develop a site where people will form communities and will blog around. They will make friends and send friend request. So its much a combination of social Networking Stuff combined with Blogging Stuff. Can somebody suggest that if I should go for WordPress or look for some other option like. ELGG.
Take a look at the < plugin
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "buddypress, social sharing" }
permalink %year% of pre-written posts to be published next year, in the mysterious future (*) I am pre-writing some posts that will be published next year. My permalink structure is /%year%/%postname%/ After setting the post title, the permalink says it will be which reflects the year I'm writing it. But I'd like it to be because it will be published in 2012. I tried setting the publish date _before_ writing the title, but the permalink still says it will be 2011, even though the publish date is set to be next year. **How can I make the permalink reflect the publish year instead of the current year?** (*) I tried to make my question title include all the keywords I used trying to search for this answer. After reading the note after this answer regarding scheduling posts, I wonder if I simply have to wait until next year...
After clicking [publish] once or twice, the permalink fixes itself automagically; I didn't see it before because I didn't want to save with the "wrong" permalink.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "permalinks, scheduled posts" }
submit for review issue I have installed WordPress on my linode vps and it was running without a problem till today. Today I realized I dont have admin rights to post a page in wp-admin. It doesn't show me submit button, it shows me "submit for review" button instead. It is very odd because I am logged in with admin account and for example I can use theme editor, edit styles etc. I googled it and found something about "auto increment on primary keys are gone". What do you think?
Weird.. Have you checked the database on your own? 1. Are you in the administrator group? Get your user id from the `{tableprefix}_users` table and search for the coresponding meta key `{tableprefix}_user_level` for your user id inside the `{tableprefix}_usermeta` table. The value should be set to `10`. 2. Do you have migrated the database from another wordpress installation? If it's really an autoincrement problem, you could use a db tool (e.g. phpMyAdmin) to set the `AUTO_INCREMENT` attribute. I haven't tested this, so please make a database backup before and use a testsystem. Open your database, select a table (e.g. `{tableprefix}_posts`), click the `Structure` tab and edit the `ID` column. There you can enable/disable the `AUTO_INCREMENT` attribute for this column. Another approach is to export the hole database with the `Add AUTO_INCREMENT value` selected, delete and re-import the database.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "wp admin, review" }
How to discover and delete unused accounts? I'm running a Wordpress self hosted blog with registration and I would like to know if there is a safe way to know if users hasn't login yet or if account is unused by a long time. What I would like to achieve is to be able to automatically delete accounts that aren't unused by 6 months or more or not used at all. Any help? Thank you!
There's several plugins in the directory that will track the last login time of your users, each with various options: < You could use one of those to track login times, and then delete unused accounts based on the information one of those plugins provides.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "users, customization, account" }
How not to show leave a Reply to Home Page? I have made my Front Page as a Static Page. The Page is having a Introduction Content. I am showing this content as an introduction to the site. But it displays "Leave a Reply" Box below it. I do not want the users to give comments on this content. Can somebody suggest How to suppress this for my Static Home Page for all users except Admin.
Follow these steps: 1. Go to 'Pages'. 2. Look for the page you've set as your homepage in the list. 3. Hover your cursor over the title and click on 'Quick Edit'. 4. Uncheck 'Allow Comments' and then 'Update'. **Edit:** For disabling Trackbacks and Pingbacks (and Comments too!): 1. Open the page you've set as your homepage for editing. 2. Look for a box titled 'Discussion', and uncheck 'Allow Pingbacks and Trackbacks on this page'. 3. If the 'Discussion' box is not visible on the edit page, then click on the 'Screen Options' button which is at the very top (near 'Howdy Admin'). Select 'Discussion' from the panel. 4. Now repeat step 2. Hope this helps! If it's not clear, please let me know, I'll put a screen shot.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "homepage" }
Integrate Mailchimp to a Contact Form 7 contact form Is there an elegant way (without hacking the plugin's code) to integrate a Contact Form 7 contact form to Mailchimp, so I can have a checkbox that when selected would register the email to a Mailchimp list? Thank you
This is what finally worked for me. The code needs to be updated tho. I don't have time now to get back to the refactored code but if someone requests it I will do it in due time.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "plugins, plugin contact form 7, plugin mailchimp" }
How to Trigger comment_form_after action if comment_form() not used A plugin I want to use has a filter like so: > add_action('comment_form_after','yoast_track_comment_form'); The theme I'm using doesn't use the comment_form() call and I believe that this means the filter isn't being called. The yoast_track_comment_form just adds some jquery tracking, so what is the best way to trigger it. Should I just call it directly from within the plugin code?
You can simply place the hook yourself in your theme (or better: Child theme) template: do_action( 'comment_form_after' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "comments, actions" }
How to properly prefix blog post URL's I want to prefix my blog posts with `/news/` and changing my Permalinks to `/news/%postname%` seems to do the trick. However, I also have a few custom post types and for some reason those URL's are now also prefixed with `/news/`. Of course this is not what I want. How can I make sure that only the out-of-the-box Wordpress post type is prefixed with `/news/`?
Assuming that you are not using a plugin to handle your post types but are registering them manually: Add the `rewrite` argument to your `register_post_type()` function calls. $rewrite = array( 'slug' => $slug, 'with_front' => false ); $args = array( // your other arguments 'rewrite' => $rewrite ); register_post_type( 'name_of_your_post_type', $args ); If your registering your post types with some plugin, check whether it has an option to set `with_front` to `false`. It defaults to `true` (unfortunately, for your sake). Whether there's a plugin out there that has this feature I don't know - never used no post type plugin(s).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, url rewriting" }
How to redirect RSS feeds to Feedburner and keep pretty permalinks? There are many tutorials out there, but all of them give you the same code snippet. I put it into my htaccess file, but the feeds are not being redirected. I don't want to use a plugin. I'm sure the code works. I need to figure out why it doesn't work for me. Here's part of my code: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # temp redirect wordpress content feeds to feedburner RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ [R=302,NC,L] </IfModule> #Prevent directory indexing Options -Indexes # END WordPress
The rules for Feedburner should come before the WordPress rules. And activate the rewrite engine just once. That’s enough. :) <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ [R=302,NC,L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "permalinks, rss, htaccess, feedburner" }
Query posts in a category and include only one post per author? I'm attempting to list posts from a category (a random selection). However, I only want to display one post per author. Thoughts? Appreciate the help.
Can this help you? -- < ps. I should add this as a comment, but I can't, sorry.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query posts, author" }
Can I create a NextGen gallery from a WordPress gallery Is it possible to convert a standard WordPress gallery that I have created in a page to a NextGen Gallery? And if so, how do I do this?
Maybe someone will correct me, but I believe your answer is no. The reason I say no is because NextGen creates additional folders that contain your gallery images. It might be possible to tweak the settings to force it to use the current images location, but that would cause issues down the road if you have your Media settings as Year\Month. I used to think that NextGen was the best gallery around and recommended it to all who asked, but now I don't use it because it leaves a mess behind if you decide to use something else.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "gallery, plugin nextgen gallery" }
Resizing Picture I'm new to WP and am not sure how to re-size a picture. I want to scale down the pic of the guy on this page: < If you view the page source and find the source of the picture, it already has height and width attributes assigned to it. When I edit these attributes in Notepad++ and re-upload them to my server the page still looks the same (yes I am clearing my cache) How can I change these attributes? Any edits I make to to "index.php" never show up, but edits to "style.php" seem to always work. Thanks
#sidebar_img img { width: 250px !important; height: auto; } #sidebar_img { text-align: center; } use this css.. change 250px with whatever you want.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "sidebar, images" }
Show category name, and last 5 post titles below category name? Is there a function that will let me display a category title and the last 5 post titles from that category just below it? Is there a loop which can do this and list post titles of that category in an un ordered list with the category title just above outside the loop?
you haven't stated where the category id will come from, nor how you want to style the category title, and if the post titles are supposed to be linked to the single post; therefore just the basic structure: <?php $cat_id = 137; echo '<div class="category-title">'.get_category($cat_id)->name.'</div>; $cat_posts = get_posts(array('category__in' => array($cat_id), 'posts_per_page' =>5)); if($cat_posts) { echo '<ul class="category-posts">'; foreach($cat_posts as $cat_post) { echo '<li class="category-post">'.get_the_title($cat_post->ID).'</li>'; } echo '</ul>'; } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories" }
Wordpress comment_form() does not display actual comments Maybe I did not understand the role of comment_form(). **After pasting this in my wordpress single.php I get just the form for submitting comments but NOT THE ACTUAL COMMENTS.** Is this a bug, or the comment_form() does not handle listing the comments? Ty!
to list comments use wp_list_comments() functions' names tell for themselves, your CO
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, comments" }
Pasting this PHP breaks my page. Why? I tried a few echo commands, and they return properly. **Breaking Statement** <?php $gallery_ids = $wpdb->get_results( "SELECT gid FROM ".$wpdb->prefix."ngg_gallery ORDER BY gid ASC", ARRAY_A); ?> This causes anything after this statement not to show up, consequentially breaking the page. If I do things like this : <?php $custom_query = new WP_Query( 'posts_per_page=3&cat=1' ); if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?> <p id="title"><?php the_title(); ?></p> <p id="small-date">Posted on: <?php the_time('F j, Y') ?></p> <?php the_excerpt(); ?> <hr /> It works fine. So I know it can take complicated PHP statements. I'm curious why my previous statement would break..
Make sure you reference the global `$wpdb` variable first, otherwise PHP doesn't know what `$wpdb` is or whether or not it has a `get_results()` method or a `prefix` property. So just add `global $wpdb;` to fix it: <?php global $wpdb; $gallery_ids = $wpdb->get_results( "SELECT gid FROM ".$wpdb->prefix."ngg_gallery ORDER BY gid ASC", ARRAY_A); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, php, pages" }
Archieve page, Advertisement Every 3 Posts Currently this code < is displaying 10 posts because I set it in the Reading settings. Now what I want is to display a advertisement(widgetize) every 3 posts... how can I do that?
$i = 0; while (have_posts()) { $i++; the_post(); // Output the post the_title(); the_content(); // Output an ad after each third post if ($i % 3 === 0) { echo 'ad'; } } The `%` is called the modulus operator.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, pages, archives" }
Suspicious mesage appears instead of images My installation is of Multisite setup . when I upload an image and try to view it, getting a message 'go home baby!!' instead of image Actually the specific sub-site is also mapped with a custom domain. I thought that it is breaking the link. So removed the mapped domain and still having the same issue Tried uploading multiple images and almost every image gives the message. Is that kind of some fraudulent activity or my files were hacked? I don't think so . I have checked the installation files and nothing suspicious found Could any one help me with this?
The only reference I can find is this: < Check your ms-files.php is the one bundled with WordPress and hasn't been modified
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, errors, images" }
How do I create a Meta box that can be repeated? (with an image section and text area) What I need to do is have a meta box that you can select an Image (via the built in media uploader), and then add a caption to it using a text box with the TinyMCE bar - and once this is done, another one can then be added below if needed. I found a similar question, with an answer, here: Create more Meta Boxes as needed but I am not sure how to adapt it to my needs. I know this kind of functionality is possible with Advanced Custom Fields, but I would prefer to be able to learn to build this functionality myself. I hope this makes sense!
I've accomplished this using the WPAlchemy library. Might not meet completely your "do it myself" requirement, but the functionality is there and you can tweak it to accomplish a lot without having to code everything from scratch.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "metabox, custom write panel" }
Get thumbnail URL :) I try to get thumbnail URL correctly... In my functions.php, I have theses lines: <?php add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 'emphasis', 132, 82, true ); ?> <?php function w_thumbnail_src() { if (has_post_thumbnail()) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis'); echo $thumb[0]; // thumbnail url } } ?> The thing is, I don't get the correct size in my template :( I have this: <?php w_thumbnail_src(); ?> That returns the big image, not the thumbnail :( Where am I wrong? Regards, Alex
You are not using `set_post_thumbnail_size` properly. Try with: add_image_size( 'emphasis', 132, 82, true );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images" }
Permalink to user profile How can I retrieve the permalink to a user (author) profile dynamically outside the loop by ID? an alternative to `the_author_link()`, but for outside the loop. ### Example: get_author_link($user_id);
I believe the function you want is get_author_posts_url.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "author, permalinks, profiles" }
How to make modifications only to certain elements of an HTML string on the server-side? Is there a similar way to select / perform DOM manipulation on the server-side (PHP) like the way jQuery works? For example, if I wanted to modify content of each `<pre class="raw">...</pre>` elements inside of a post content, in jQuery you can easily capture them all with: //In jQuery, this will obtain a collection of <PRE> elements with class "raw": $("pre.raw").each( function(index,tag) { //Modify content of each PRE tags here... tag.innerHTML = tag.innerHTML.replace( ..., ... ); }); In PHP however, I'm trying to do this by adding a filter to "the_content", which will then do some string replacements only inside each of those `<pre class="raw">` elements. Does WordPress already have some built-in utility method to grab elements this way? Or does some 3rd party PHP script exists that will do this?
You may also take a look at phpQuery.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, functions, html, filters, parse" }
Setting variables as custom field values I have a function that performs some custom queries to get specific information regarding a post (children count, dates, etc). I am wondering if it is possible to send this custom query info (set as a variable) to a custom field automatically when I update the page.
Sure. Hook into the `save_post` action, then perform your custom queries upon save, and store them as custom fields of the post. add_action('save_post', 'my_extra_meta_saver'); function my_extra_meta_saver($post_id) { global $post; // Prepare whatever extra information you want here // Save each piece of info in a custom field update_post_meta($post_id, 'meta_key', 'meta_value'); }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization" }
Control Custom Post Type template from a plugin I can control the custom template to be used on custom post type pages but the template file would still need to have the markup of the theme. I was wondering if I could make it theme independent? Example: I have a plugin that registers my custom post type. I have the post meta info that I want to show in a custom template. I have that template working on my custom post type pages but the max I could do is to use get_header() & get_footer() calls but I can't deal out the need of having the theme markup between header & footer. Did that make any sense? Any ideas?
I have got it working by the following code: add_action( 'template_redirect', 'ft_job_cpt_template' ); function ft_job_cpt_template() { global $wp, $wp_query; if ( isset( $wp->query_vars['post_type'] ) && $wp->query_vars['post_type'] == 'job' ) { if ( have_posts() ) { add_filter( 'the_content', 'ft_job_cpt_template_filter' ); } else { $wp_query->is_404 = true; } } } function ft_job_cpt_template_filter( $content ) { global $wp_query; $jobID = $wp_query->post->ID; $output = ''; // Build markup fetching info from postmeta return $output; } Feel free to comment on any suggestions.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "custom post types, page template" }
Get list of all registered post types slugs I'd like to get a list (array) of all the post types I registered. Precisely I would like to retrieve their slugs. Could someone help me? thanks!
@EAMann's answer is correct, but there's already a build in WordPress function for fetching all registered post types: `get_post_types` <?php // hook into init late, so everything is registered // you can also use get_post_types where ever. Any time after init is usually fine. add_action( 'init', 'wpse34410_init', 0, 99 ); function wpse34410_init() { $types = get_post_types( [], 'objects' ); foreach ( $types as $type ) { if ( isset( $type->rewrite->slug ) ) { // you'll probably want to do something else. echo $type->rewrite->slug; } } }
stackexchange-wordpress
{ "answer_score": 11, "question_score": 6, "tags": "custom post types, slug, array, post type" }
Page is defaulting to archive page and not designated template 1. I created a page called "Projects" through the wordpress admin 2. I created a template called "Projects" 3. Set the "Projects" page to use the Projects template. How come when I navigate to the Projects page it shows the archive page and not the Projects template. Also, if I set the "posts page" in settings->reading to "Projects" in the admin then the above happens. But, if I don't set a post page then I can go to the /Projects and this works fine. However, if I go to /projects (lowercase) then this doesn't work and it defaults to the archive page. I'm confused as to what is going on, can anyone help?
This conflict normally happens when a custom post type archive and a normal wordpress page has the same slug. The custom post type archive has the higher priority here. If you have a custom post type by the name 'Projects' and 'has_archive' is set to true for the custom post type then the conflict will arise. Set 'has_archive' to false so that it shows the page template. Or you could also create a archive-[post-type].php and style it in accordance with your portfolio page template.
stackexchange-wordpress
{ "answer_score": 13, "question_score": 3, "tags": "custom post types, templates, custom post type archives, archives" }
Specifying a template for custom post type pages My main projects page is bringing in some data that I have entered in for custom post types. There are basically a few categories like "photo", "video", etc. When you click on one of these it will go to a subpage like /projects/photo/1. How to I go about specifying a template to use for those subpages? I am using the Ultimate Post-Type Plugin, but that shouldn't really matter since it should work the same way.
Have a look at the template hierarchy that WordPress follows. Since the sub page is a single custom post type. You could put the code you require to output for the sub pages in single-[post-type].php
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, templates, custom post type archives" }
How can I include author (their archive page) in search results? How can I include author archive pages in the default search results? For example if I have an author name Billy Joe and I type his name into the search box a link to his author archive would display.
Relevanssi can be configured to search in author names. !enter image description here It doesn't search in author descriptions.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "search, author" }
Exclude post from home page and archives, but still public Can a post be hidden from home page, archive view, category lists etc. and viewable only if you have a direct link to it? The blog doesn't have registered readers and is open to public so that would be a mean of hiding some posts from public view without using the password protection.
I found the simplest way - just use Simply Exclude Wordpress plugin. It has the option to exclude each post (or tag, for that matter) from front page, archive, search or feed. It works flawlessly. You can still view the posts by using direct links.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "private, privacy" }
WordPress Google Maps Does anyone know of a nice map plugin for WordPress? I have a diary website in WordPress where each diary entry has the latitude and longitude of where each post was written. I thought it would be cool for each post to have a google map showing where each entry was written. Maybe even show the path that was taken while writing the diary. Any ideas?
There is one and two really interesting ones at the general plugin database. Slightly different with their layout options, but they both take data input (coordinates and what-have-you) in plenty of formats. hope that helps, J
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "google maps, map" }
get_posts only children from certain parents I have parent posts (custom post type hierarch=true) with ID 1, 2, 3, 4. The parent posts with ID 2 and 4 have child pages. I need to retrieve only posts 2 and 4 and all of their child pages. Something like this $argsch = array('orderby' => 'date','order' => 'DESC','post_type' => 'products', 'include' => '2, 4'); $childs = get_posts($argsch); How can I edit this to return child pages of the included id's?
You have two options: 1. Call get_posts multiple times: one for the parent pages using `post__in => array(2,4)`, and two for the child pages of each parent with `post_parent => 2` and `post_parent => 4` and finally merge all the results into a single array. 2. Write directly your SQL query and use `$wpdb->get_results`. See this article for an example. In your case it would be something similar to the following (not tested) code: $query_sql = " SELECT * FROM $wpdb->posts WHERE post_type = 'products' AND (ID IN (2,4) OR post_parent IN (2,4)) ORDER BY post_date DESC "; $query_result = $wpdb->get_results($query_sql, OBJECT);
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "get posts" }
wp_usermeta wp_usersettings I would like to know what does these meta_value means for wp_usersettings meta_key in wp_usermeta table? * meta_key: wp_usersettings * meta_value: m1=o&m3=o&m0=o&m2=o Thanks
When a user changes their admin settings; like the screen options, posts per page or moves metaboxes around or 'hides' them, it is saved in their user settings. So if user settings are blank - the user has never tailored their admin environment. Aside: (I use this to great advantage in one of my plugins to simplify the backend initially but allow users to 'grow'. IE - a 'template' user can setup how they would like the admin environment to look by closing meta boxes, changing columns displayed etc. Then when a new user is created, i have the template user settings copied over to new user to present a simplified admin backend. The new user can then add back features as they learn more. I love it!)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "options, user meta" }
Only allow plugin to be activated on root site of multisite I'm developing the wordpress file monitor plus plugin. Its purpose is to scan for altered files and it works fine for a single installation of WP. But when you look at multi-site it's not something that wants to be enabled on all sub sites, as they all share the same files and (to be honest) only a network admin should be the one that wants to be notified against file changes. So my question is this: > How would I program it, to only be allowed to be installed/run from the root site of a multi-site installation? So: that means not allowing it to be network installed and only activated from the root blog. Anyone know of any ways on how I could achieve this?
You could check if the constant `SITE_ID_CURRENT_SITE` matches `get_current_site()->id`. The following does this for the activation. During runtime you have to check it again. register_activation_hook( __FILE__, 'force_main_site_installation' ); function force_main_site_installation() { if ( defined( 'SITE_ID_CURRENT_SITE' ) and SITE_ID_CURRENT_SITE !== get_current_site()->id ) { if ( function_exists('deactivate_plugins') ) { deactivate_plugins( __FILE__ ); } die( 'Install this plugin on the main site only.' ); } }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "plugin development, multisite, activation" }
Removing fields from category/taxonomy edit form Terms like 'slug' and 'description' on custom taxonomy edit pages tend to mislead my client. Is there a way of removing these from the page flow? At the moment I'm using JavaScript, which isn't ideal. I was looking at `{$taxonomy}_pre_edit_form` and its ilk, but none of them seemed to offer the fields for editing. Thanks,
Looking at the source (edit-tag-form.php) it doesn't look like there is a way of doing this through filters, as the code is directly outputted as oposed to being held in a variable. All `{$taxonomy}_pre_edit_form` does is allow you to add code before the form. JS I think is the only way, and to be honest it's not a bad way - it sould only be a few odd lines, and if it achieves what you want, then it's surely good news.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, wp admin" }
Check if date of post is yesterday In a loop, I want to display "Yesterday" if the date of the post(s) are dated from yesterday... So here it goes: <?php if( date('Yz') == get_the_time('Yz') ) { echo 'Today'; } elseif ( date('') == get_the_time('') ) { echo 'Yesterday'; } else { the_date(); }; ?> Would you guys know the correct syntax on the elseif line? Best regards, Alex * * * Well, I can't answer my question yet because I'm a noob (not enough reputation). So here it is: <?php $w_h = $w_d = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php if ( date('Yz') == get_the_time('Yz') ) { if (!$w_d++) echo 'Today<br />'; } elseif ( date('Yz')-1 == get_the_time('Yz') ) { if (!$w_h++) echo 'Yesterday<br />'; } else { echo the_date(); }; ?>
As you discovered, one possible solution is something like: <?php $w_h = $w_d = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php if ( date('Yz') == get_the_time('Yz') ) { if (!$w_d++) echo 'Today<br />'; } elseif ( date('Yz')-1 == get_the_time('Yz') ) { if (!$w_h++) echo 'Yesterday<br />'; } else { echo the_date(); }; ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "loop, date" }
Add the last viewed post title to a contactform with shortcode I'm using the **contactform 7** plugin and i want to add the title of the last viewed page (The page visited before the contact) to the dynamic field of the plugin with a shortcode. Is there a way to do that? I found this plugin Last Viewed Posts to display the last visited post. But I can't found a solution to add this to the dynamic field of my contactform. Would be very nice if someone could help me. Thanks, Oli
I think the best way to do this would be to use the Contact Form 7 Dynamic Text Extension, and then pre-populate the URL to the Contact Form page with the current post title. More details on how to do that in my answer here. The code to pre-populate the link in a post template would look something like: <a href="<?php echo get_page_link(58); ?>&foo=<?php single_post_title(); ?>">Contact Form</a>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "shortcode, title, plugin contact form 7" }
Preferred Method of debugging a wordpress SQL calls? What is your preferred method of debugging Wordpress Applications when writing custom behind-the-scenes SQL calls, etc. ? Coming from a Rails background, I usually tail a log file that displays not only all the processes and views that are being seperately loaded into a template, but if there is an error, it will pin point the **exact** location of the error, with a suggested idea of what went wrong. I noticed that in WordPress, you can set up a debug.log file but it only shows a _very_ barebones version of this, and rarely points to what actually is failing. Any recommends?
Turn on `define( 'WP_DEBUG', true );` **_and_** `define( 'SAVEQUERIES', true );` . I prefer the format of the debug bar, < , which can be combined with the console, < . This script is great for profiling, Best Collection of Code for your functions.php file There are some other plugins that might help, like Debug Queries, but you probably going to have to use a debugger like xdebug to get more fine grained details.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, sql, debug, logging" }
A proper gallery in wordpress? The dad from a friend of mine photographs bird feathers for hobby. He has about 6000 of them. I've been asked to find him an easy to use gallery, which should allow some kind of batch processing as it's a lot of photos. I've started off on Gallery2, but we're not on speaking terms anymore; what a piece of shit. Any suggestion of building a gallery in Wordpress? Key features: folders, batch processing. Thanks!
WordPress can do a lot with images provided it's configured right, and exactly how you want it. < will give you the basics to then customise to your requirements. A great example of this kind of thing can be seen on Matt Mullenweg's site: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "gallery" }
Does a Google + RSS Plugin Exist? There are post to Facebook/Twitter plugins but I can't find one for Google Plus. Does anybody know if such a plugin exists or if there is a better solution? It would be nice to have content automatically post to a Google Plus page!
Here is a plugin to display your Google+ feed in a widget: < However, the reverse, of posting from WordPress to a Google+ profile/page is not possible, as the necessary API calls aren't available in Google+. One can read from a profile/page but not write.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, google plus" }
Inserting a DIV Block Into a Listing of Excerpts? I'm sure there has to be a tutorial for this, I just can't find it. I'm also pretty confident there's numerous ways to do this and I'm looking for the best. I've never had to do this before, so I've never asked... I want to insert a DIV into a list of excerpts. For example, take a look at: < where Orman added a div asking users to subscribe into his excerpts.
add a counter to your loop or use a conditional statement with `$wp_query->current_post`, just before the 'endwhile', and add the div when the counter/post number reaches a certain value. please paste the full code of your template into a < and post the link to it here, if you need more details.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "css, excerpt" }
Add user capability and check against it I just realized the following: // Call the current user info global $current_user; // Add a capability // and set the 2nd argument ($grant) to false $current_user->add_cap( 'some_cap', false ); Now I've successfully added a capability to the user, but denied her/him the access to this capability. If I now check with `$current_user->has_cap( 'some_cap' );` I'd get a `true` in return. The same goes for `current_user_can( 'some_cap' );` as this is only a wrapper for the has_cap functions arguments. **Q:** Where is the 2nd argument used? Did I get something wrong?
I think you are using it right. I think it is actually a bug in WordPress. When you do the same for roles `$somerole->add_cap( 'some_cap', false );`, it works as expected.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "capabilities, user access, users" }
How to import content from WordPress.com to a self hosted WordPress installation? On behalf of another, I'm trying to import content from a WordPress.com hosted site to a self-hosted installation of WordPress.com I've exported the XML file and imported it into the new site, but it looks completely different. The pages are all over the place and lots of the images haven't imported. Any ideas how I can get an exact mirror?
It looks like you may need install and configure a slideshow plug-in (example: under Vertical Blinds). The shortcut "[slideshow]" in the text is what tells the plug-in to run a slideshow. The menu items under "Our Blinds" are in a different order - if there is a custom menu, configure it under Appearance-> Menus. You may not be able to do it 100% automated.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "import" }
jQuery UI styles conflicting with TinyMCE dialog I'm using jQuery UI for a few custom controls on the page edit screen and I've noticed that the styling of the jQuery UI dialogs are conflicting with the TinyMCE dialog. Specifically the buttons and title area look especially bad. I've looked through the jQuery UI css to see what could be removed to avoid any conflicts and they're spread pretty much throughout the whole stylesheet. Is there a way to run both together without conflicting?
Turns out what I had to do was use the CSS Scope option in the jQuery UI download application. I was using the normal wp_register_style/wp_enqueue_style to put it in place and it would always conflict with the jQuery UI dialog styling that the Wordpress install of TinyMCE uses. After switching to using a scoped version of the jQuery UI styles everything worked fine.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "css, tinymce, jquery ui" }
How to add categories to page editor? I'm trying to add the categories selector to the "page" editor workspace. The code below does the trick, however, none of the values are saved with the page. Any help much appreciated! add_action('admin_menu', 'my_post_categories_meta_box'); function my_post_categories_meta_box() { add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'page', 'side', 'core'); }
You'll need to register the `category` taxonomy for the page `post_type` with `register_taxonomy_for_object_type`. This does the trick: <?php add_action( 'init', 'wpse34528_add_page_cats' ); function wpse34528_add_page_cats() { register_taxonomy_for_object_type( 'category', 'page' ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "metabox" }
Open Graph in Index Loop I have an index of posts where I'm wanting to insert a Facebook Like button for each post. Thus far, I've set all Open Graph data in the head for single posts. Any ideas on using the open graph data (particularly, the thumbnail) within the loop?
Short answer: you can't do that, that's not what OpenGraph data is, does, or how it works. Long answer: OpenGraph applies to the single post pages only, realistically. When you're putting a like button (for example) onto each post on a archive page, the like button is going to point to the permalink of the single post. That's where FB will look for the OG data for that particular like, not on the archive/home page. Best answer: Don't DIY it. Just install my Simple Facebook Connect plugin, and let it do all the OpenGraph grunt work for you automagically. I just added support for Audio data, and I'm improving the video handling now. SFC 1.2 will have some great functionality there. :) <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, facebook, open graph" }
Add custom read more to the_excerpt and <--more--> My today's question is... is there any way to auto add an custom (whatever I want) Read more... each time I use the_excerpt or get_the_excerpt function??? Thanks in advance
From Twenty Ten's functions.php: /** * Returns a "Continue Reading" link for excerpts * * @since Twenty Ten 1.0 * @return string "Continue Reading" link */ function twentyten_continue_reading_link() { return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>'; } /** * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link(). * * To override this in a child theme, remove the filter and add your own * function tied to the excerpt_more filter hook. * * @since Twenty Ten 1.0 * @return string An ellipsis */ function twentyten_auto_excerpt_more( $more ) { return ' &hellip;' . twentyten_continue_reading_link(); } add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "excerpt" }
Create a slug for a page in WordPress How can I create a slug for a page in WordPress? I see that there are custom formats available, but I would like to be able to specify things like: mydomain.com/about mydomain.com/home mydomain.com/portfolio etc. Is there a plugin or technique that I could use to accomplish this?
The custom permalink you will most likely want to use is /%postname%/ Which will get the structure that you show above. (mydomain.com/about, mydomain.com/home) If you want to edit the slug, it's right underneath the title of the post ("Permalink"), click edit.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, seo" }
RSS Subscriber count I'm looking to retrieve an RSS Subscription count. How do I return the number of subscribers without use of Feedburner or use of a plugin?
A reliable subscriber count is not possible, unless you require registration to access your RSS feeds. For example, my site is being autopolled by 5 other sites using auto aggregators, including 2 or 3 devices of mine, including Google Reader. I count as 1 subscriber, yet if I counted subscribers by how many accesses I get, I now count as 9 or 10 subscribers. ( Until recently even the Googlebot search indexer would show up here ) What may be a better approach is to make your RSS feed items links to your posts, rather than containing your posts in their entirety. You would annoy a few people, but you'd be able to track users arriving via Google Analytics, giving a much better view of how many people use your feeds, and removing the automated components.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "rss, feed, count" }
WP Config for FTP credentials Is there a config in WP that allows you to store your FTP credentials? I'm using the Linux webserver at work to develop and it's really annoying to have to but the credentials in every time I add/remove a plugin/theme. Anonymous access is a no-no, so I hoping that this config exists... Thanks.
define('FS_METHOD', 'ftpext'); define('FTP_BASE', '/path/to/wordpress/'); define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/'); define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/'); define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub'); define('FTP_PRIKEY', '/home/username/.ssh/id_rsa'); define('FTP_USER', 'username'); define('FTP_PASS', 'password'); define('FTP_HOST', 'ftp.example.org'); define('FTP_SSL', false); <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "plugins, themes, wp config, ftp" }
WordPress strips some attributes for author posts I added template to my WP posts, so when you click Add New content area alreday with text. Template smt. like this <div id="myDiv"><p>Add your text here</p></div> If user has Admin or Editor roles then it works great, but if user has Author role id sprips, and I got <div><p>Add your text here</p></div>
WP stripts HTML for authors. I had this problem too. I'm sure this post can help you. How can HTML be allowed in Author Bio? or this: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, user roles, customization" }
Defining 'last' class on foreach blog posts I'm using the following code to display the latest 3 blog posts on my front page but I need to add a `last` class to the 3rd post on the ID `blog`. <?php $args = array( 'numberposts' => 3 ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?> <div id="blog"> <div class="blog-header"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> <div class="date"> <?php the_date(); ?> </div> </div> <?php the_excerpt(); ?> </div> <?php endforeach; ?> What do I need to add to achieve this?
Something like this should work for you. $args = array( 'numberposts' => 3 ); $lastposts = get_posts( $args ); $count = 1; foreach($lastposts as $post) : setup_postdata($post); ?> <div id="blog" class="<?php if ($count == 3) : ?>last<?php endif; ?>"> <div class="blog-header"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> <div class="date"> <?php the_date(); ?> </div> </div> <?php the_excerpt(); ?> </div> <?php $count++; endforeach; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, php, loop" }
Dynamically textarea with TinyMce editor I need to used TextArea with Wysiwyg editor. That works when textarea is write on page ( Not dynamic , static ).. but my problem is for dynamically textarea. My code : add_action('admin_head', 'load_tiny_mce'); function load_tiny_mce() { // The 'mode' and 'editor_selector' options are for adding // TinyMCE to any textarea with class="tinymce-textarea" wp_tiny_mce(true, array( 'mode' => 'specific_textareas', 'editor_selector' => 'tinymce-textarea' )); } I added textarea with javascript code when i push a button. textareas is basic not with wysiwyg editor ... ! I think i need to bind function ... but how to ! I hope, you understand me .. ! Regards
Add this function to you JavaScript: function textarea_to_tinymce(id){ if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) { tinyMCE.execCommand('mceAddControl', false, id); } } then when you create the textarea dynamically call it and pass the textarea's id to it. Just make sure TinyMCE is loaded on that page before or it won't work.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "wysiwyg" }
Group posts by date with a list I want to set a group of posts grouped by date as a list. Below is what I would like to have: Day... <ul> <li><a href="#">Lorem ipsum</a></li> </ul> Previous day... <ul> <li><a href="#">Lorem ipsum</a></li> <li><a href="#">Lorem ipsum</a></li> </ul> I did that: <?php while (have_posts()) : the_post(); ?> <?php the_date(); ?> <li><a href="#"><?php the_time(); ?><?php the_title(); ?></a></li> <?php endwhile; ?> I don't really know where to put the < ul > or < /ul > tags. Any idea? Actually, setting the starting tag is OK by doing this: <?php the_date('','','<ul>'); ?> But I can't figure out how to set the closing tag. Regards, Alex
I usually perform a simple check to see if that day has changed. <?php $day_check = ''; while (have_posts()) : the_post(); $day = get_the_date('j'); if ($day != $day_check) { if ($day_check != '') { echo '</ul>'; // close the list here } echo get_the_date() . '<ul>'; } ?> <li><a href="#"><?php the_time(); ?><?php the_title(); ?></a></li> <?php $day_check = $day; endwhile; ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "loop, date" }
Category List With Comma & Link Trying to list the categories for post separated by a comma with link to the category archive. <?php foreach((get_the_category()) as $category) { if($category->name==$homecat) continue; $category_id = get_cat_ID( $category->cat_name ); $category_link = get_category_link( $category_id ); echo '<span class="cat"><a href="'.$category_link.'">'.$category->cat_name.'</a></span>'; } ?> Thanks for any help!
You can use the_category if you are in the loop: `<?php the_category(', '); ?>` If not, then use this code: <?php $output = ''; foreach((get_the_category()) as $category) { if($category->name==$homecat) continue; $category_id = get_cat_ID( $category->cat_name ); $category_link = get_category_link( $category_id ); if(!empty($output)) $output .= ', '; $output .= '<span class="cat"><a href="'.$category_link.'">'.$category->cat_name.'</a></span>'; } echo $output; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "categories" }
My post does not show up I'm facing a WordPress strange behavior. One of my posts is not showing up. If I open post editor I can find the post full text and in my home page I can see an excerpt of this post. Does anybody have any idea how to fix this?
You other posts are very much visible.This seems to be a strange behavior indeed.Your blog seems to be good enough performance wise. I would suggest you try to delete the post and prepare a new one . May be this must solve the problem .
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, errors" }
Add .html extension to only one page in my Wordpress site We had an old site that had html pages in it. One of the pages in that site was linked to from many other sites. Now we moved to a WordPress site, and we created a page with that name, but of course it doesn't have the ".html" extension, so links to that page lead to an empty page... I saw a plugin that adds html extesnsions to all pages, but I don't want that - I have only one page to which I want to add .html. What can I do to accomplish this?
I would just add a rewrite rule to your .htaccess file of something like: `Redirect 301 /oldpage.html see: <
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "url rewriting, html, customization" }
Google Map Latitude and Longitude values in form I have a front end submit form and would like to include a two extra custom fields which will hold Latitude and Longitude values. I want the users to select the location on a map which will be included in the form. Anybody know a good way of doing this, or any tutorials? Thanks!
Take a look at this I did for a client: < A user can click the map and choose where to search. When a user clicks it updates a couple of hidden fields. Feel free to look at the source code to see how its done. If you want a more in depth description of the google maps api and javascript then this question would be better asked on stackoverflow
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "forms, google maps" }
How could a Widget behave differently depending on sidebar if sitting on sidebar-1, I need my widget to behave differently than if it were on sidebar-2. How can i detect the sidebar it is sitting on from within the widget() function? The widget contains a list of links to posts. Depending on which sidebar, it should use a different custom image size version of its thumbnail. So what will change is the thumbnail size reference name. For instance, in one sidebar, "xs-square-thumb" will be used; in another "L-square-thumb" will be used. Ex: `get_the_post_thumbnail($post->ID,'xs-square-thumb');`
there isnt a clean way of handling this, since there isn't a conditional for checking which sidebar is in use, just whether or not it exists. however, you could do the following: 1. make two different versions of the widget (which would make it "future proof" in regards to what widget names could exist). 2. add a checkbox to the widget options to choose which size image to use.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "widgets, sidebar" }
I need advice on how to structure the categories according to the layout i have I'm seeking advice on how to structure the categories so it fits well my page structure: !The page structure The main highlight is a single post and the secondary highlight boxes will probably contain a slides showing more than one post each, and the grid at the bottom will have four posts. I don't know how i can categorize that and still mantain a good category structure, or if using taxonomies is a choice or not. Or maybe tags... i'm kinda lost. If it counts, i'm extending the Starkers theme. Thank you. EDIT: For clarity's sake, here's the link to the html version: <
It's not really a category issue unless you want different areas to only show different actual categories. What I've normally done in this case is either use custom fields or set up a custom 'presentation' taxonomy so on a post I can check a box to say "this post is a 'Main Highlight'" or "this post is not-so-important" and then use multiple queries on the page to fill each of those post-areas. In your case one query for main highlight with one post, one query for secondary highlight with multiple posts, another query for secondary highlights (2) with multiple posts and then one final query for Not-So-Important with four posts. Doing it with custom fields is basically the same thing I suppose... I try to keep the default categories clean because then I can output them on a post for thematic archives, without having presentational categories wind up in the list.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, frontpage, customization" }
WordPress file manager plugin I would like to manage some files available for download from my WordPress page. Because the file should be attached to more pages I would like to define pages where file is avalable for file directly. I don't want define the same file for lot of pages in my application. Do you know some plugin which should help me with this?
I solve this issue myself. I used `file-un-attach` plugin, which allows attach same file to more pages. This plugin uses custom find method which finds by text in title and content. If you write `""` (double quotes) into search box it will find all pages in application. Result set is limited to 50 rows - it is possible remove it in `file-un-attach/ajax.php` Hope will help others.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, file manager" }
header_image not working after site copy I did a copy of a production site to a development site, but the header_image doesn't work after the copy. The copy was done by doing a copy&replace of the host in the db dump file. Everything seems to work except that I now only get the default custom header image and not the one that was earlier configured for each site. I have looked into debugging this issue, but it gets complicated. Has anyone experienced this issue and know how to solve it?
It is not recommended to make a simple search&replace in the dump file when moving to another host, because of the presence of serialized data in some database fields (usually options fields of core and plugins). I would recommend to use one of the following migration plugins/scripts to handle the data conversion when moving Wordpress: 1. Wordpress Move (WP plugin) 2. Search and replace for Wordpress (PHP script)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "clone site, header image" }
Efficient way to fetch all archived WPMS blogs is there a good and efficient way to fetch all WPMS blogs with archived set to true? Because there doesn't seem to be a function to get all blogs I have added the admin user to all blogs. Then I do a `get_blogs_of_user(1, false)`. This fetch all blogs that are active, but I'm looking for an efficient way to fetch all blogs that is archived. I guess I can do something complicated e.g. call `get_blogs_of_user(1, true)` then `get_blogs_of_user(1, false)`, then find the difference and check if they have the archived bit set one by one, but is there some better way to do this? Thanks.
You can go directly to the database via `$wpdb`. <?php $wpdb->get_results( "SELECT * FROM $wpdb->blogs WHERE archived = 1" ); Or wrapped up in a function: <?php function wpse34731_get_archived_blogs() { global $wpdb; if( empty( $wpdb ) ) return; $blogs = $wpdb->get_results( "SELECT * FROM $wpdb->blogs WHERE archived = 1" ); return $blogs; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, list" }
get_page_children arguments - page objects? From the Codex, I'm using this function to return all children from a page ID without using SQL queries. Usage: <?php get_page_children( $page_id, $pages ) ?> $page is defined as a "List of pages' objects". What are examples of page objects I would use in this case?
They give you an example on that page by using WP_Query to query for all pages, then `get_page_children` just filters that list. the "without using SQL queries" part is a bit of a misnomer, since you have to have already queried the database at some point to get those pages. if you don't already have a result to filter, then something like `get_children` or `get_pages` might be simpler.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "get children" }
Add 'title' attribute to stylesheets with wp_enqueue_style() Read below if you want to start from where I left off in core. But the basic question is: I need to add a "title" attribute to my stylesheets and wp_enqueue_style() doesn't allow for that parameter, as far as I can tell. Other than a hard embed, are there any ways WordPress allows us to add the title to a stylesheet? In digging around core I notice that there's a `$title` variable that can be set using `$style->extra['title']`. $title = isset($this->registered[$handle]->extra['title']) ? "title='" . esc_attr( $this->registered[$handle]->extra['title'] ) . "'" : ''; (class.wp-styles.php) And $title also figures in the filter that is applied when you enqueue a stylesheet. So how can you set that 'extra' array within the style object?
Okay, here's where I'm at with a solution. wp_enqueue_style( 'my-handle', 'mystyle.css' ); global $wp_styles; $wp_styles->add_data( 'my-handle', 'title', 'my_stylesheet_title' ); Don't like using the global. Is there something better?
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "wp enqueue style" }
Keep post's draft date after publishing? I let users add posts in draft status. After I check and see that everything is ok, I publish them. I noticed that drafts created two days ago change date after being published. Is there any way of keeping that original date?
you need to manually set the publish date.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "draft" }
How to make user accept license agreement before download I use my Wordpress site to host downloads, among other things. According to German law I need to make a user accept the license agreement prior to being able to download a program. I am thinking of displaying the license agreement in a pop-up window similar to the way Codeplex does it (see this page and click on download). **How can I accomplish this easily in Wordpress?**
Not being able to find anything I finally went ahead and created the WordPress plugin Terms before download. From the plugin's description: > Terms Before Download adds a shortcode that can be used instead of HTML anchors to link to downloadable files. If such a link is clicked a popup dialog shows terms and conditions (EULA) which must be accepted for the download to start. > > The terms and conditions are read from a WordPress page. That way there is only a single place to maintain the terms and they can easily be displayed independently of the plugin. > > The plugin supports Google Analytics to keep track of the number of downloads.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "users" }
using admin functions on frontend I'm updating my plugin to rely on internal functions of WordPress. I'm about to use `wp_generate_attachment_metadata`, but this function seems to be only available in the admin section. Is there an easy was to enable it on the frontend as well?
Put the following line before using the function. require_once( ABSPATH . '/wp-admin/includes/image.php' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, functions, admin" }
WordPress Following? Social Users? I'm building an extensive user backend on a WordPress news website. One of the features I've noticed many major sites have is the ability for logged in users to follow headlines from users or categories they select. Forbes took the technology from TrueSlant in its acquisition and I know as a fact it is WordPress. Is there a similar plugin or tutorial that can help me achieve the same? I've been looking and can't find one. Examples: < Mashable.com (if you login)
I don't know if you know about BuddyPress or not, but they have a plugin that will help you in your quest. It is called BuddyPress Followers which allows users to follow peoples activity. It should have options in it to only follow posts and whatnot. BuddyPress also makes WordPress more "Social"
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, rss" }
WordPress Stripping Colons? I'm souping up a WP theme with the BuddyPress plugin to make a cool hybrid of sorts between the two. Anyway... I'm using the following to grab author RSS urls. **The problem being the colon ":" is being stripped on the pages and I can't figure out why. Does anybody have a solution for this?** <a href="<?php echo " bloginfo('url'); ?>/author/<?php echo $curauth->display_name; ?>/feed/">My RSS Feed</a> I have also tried simply adding http:// before the php grab of the URL, an it still strips it. I'm assuming this is a WP or BuddyPress problem.
No idea why your colons are getting stripped out. Your original code, or @EAMann's answer, should both work unless you have some very strange filter going on. But using built-in functions to get permalinks should make your life easier in general than trying to concatenate them yourself. Try this: <a href="<?php echo get_author_posts_url( $curauth->ID ); ?>feed/">My RSS Feed</a> ... that is, assuming that $curauth is the user object as returned by one of the get_user*, get_author*, or get_currentuserinfo() functions.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, buddypress, profiles" }