question
stringlengths 0
34.8k
| answer
stringlengths 0
28.3k
| title
stringlengths 7
150
| forum_tag
stringclasses 12
values |
---|---|---|---|
I have a multisite setup, with the main site being the company web site and a couple other blogs that will have different themes. I want to pull in posts from one or the other blog onto the home page of the main blog. What is the best way to accomplish this? Thanks.
|
There's a function to get one post from one blog , but that's it: <code> <?php $post = get_blog_post( $blog_id, $post_id ); echo $post->ID; ?> </code> If the blog has only one author you could also use <code> get_most_recent_post_of_user </code> . But I think the best way is to fetch the feed using <code> fetch_feed() </code> : <code> $rss = fetch_feed('http://feed.url'); // Figure out how many total items there are, but limit it to 5. $maxitems = $rss->get_item_quantity(5); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items(0, $maxitems); foreach ( $rss_items as $item ) { // Loop echo $item->get_title(); echo $item->get_content(); } </code> It uses the Simplepie API , I recently wrote an article about that Display RSS Feed in WordPress .
|
What's the best way to get posts from one multisite blog into another?
|
wordpress
|
I have a plugin install called uCan post so registered users can post and what not, but I am wanting to have two category lists for them to choose from. one is a country the other is an activity list. Now I have the two lists available but I want to exclude certain category ID's from one of the lists. Here is the code for the category lists. <code> <!-- START EVENTS CATEGORIES --> <br /> <?php if($this->ucan_options['uCan_Show_Categories']) { ?> <label> <?php echo __('Select Your Experience', 'ucan-post'); ?>: </label> <select name="ucan_submission_category"> <?php foreach($categories as $category) if($category->cat_ID == $_POST['ucn_submission_category']) echo '<option value="'.$category->cat_ID.'" selected="selected">'.$category->name.'&nbsp;&nbsp;</option>'; else echo '<option value="'.$category->cat_ID.'"">'.$category->name.'&nbsp;&nbsp;</option>'; ?> </select> <?php } ?> <!-- END EVENTS CATEGORIES --> </code> Any help would be greatly appreciated! Thank you
|
Ok then time to move my response into an answer, because it seems you just want to exclude categories from the loop in the above code.. Assuming you're alright to modify this file(a plugin update would overwrite it), then simply conditionalise your loop like so.. <code> <?php $excluded = array( 1, 2, 3 ); foreach($categories as $category) if( in_array( $category->cat_ID, $excluded ) ) continue; else echo '<option value="'.$category->cat_ID.'"'. selected( $category->cat_ID, $_POST['ucn_submission_category'], false ).'>'.$category->name.'&nbsp;&nbsp;</option>'; ?> </code> Untested, so let me know if any problems. Replace 1,2 and 3 with the IDs of the categories you wish to exclude.
|
Removing category ID's from a selection list
|
wordpress
|
I need to create a very simple contact form in the homepage with just 3 fields.Is there a way for showing the contact form without a plugin? I dont want to create a page with a contact form template for that. thk.
|
The Agregado Theme comes with a little contact form I modified for one of my themes, I guess it's ok for you to use it as long as the credits remain there. <code> <?php //Contact script created by Tim McDaniels and Darren Hoyt for the Mimbo Pro and Agregado themes, modified by Mario Aguiar cuz it didn't work. //May be re-used with credits intact if($_REQUEST['submit']): $admin_email = get_option( "admin_email" ); $admin_subject = 'Inquiry'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ' . $admin_email . "\r\n"; $body = "<blockquote> Name: " . $_REQUEST['Name'] . "<br/> Email: " . $_REQUEST['Email'] . "<br/> Message:<br/>" . $_REQUEST['Message'] . "<br/> <hr/> Remote Address: " . $_SERVER['REMOTE_ADDR'] . "<br/> Browser: " . $_SERVER['HTTP_USER_AGENT'] . " <hr/> </blockquote>"; mail ($admin_email, $admin_subject, $body, $headers); endif; ?> <form onsubmit="return(submitContactForm(this));" id="contactform" action=""> <h5>Contact</h5> <fieldset> <legend>Contact</legend> <label for="user-name">Name:</label> <input type="text" id="user-name" name="Name" class="field" title="Enter name here" /> <label for="user-email">Email:</label><br /> <input type="text" id="user-email" name="Email" class="field" title="Enter email address here" /> <label for="user-comment">Message:</label> <textarea id="user-comment" name="Message" class="field" cols="" rows="4" title="Enter comments here"></textarea> <input type="hidden" name="submit" value="1" /> <input type="submit" value="" id="homeContactSubmit" class="button" /> </fieldset> </form> </code> You'll have to add some captcha to prevent spam, but it works. I have this working on my theme Celeste .
|
show a little contact form in homepage without plugin
|
wordpress
|
The Block Bad Queries Plugin hasn't been updated recently. Is WordPress still subject to these types of malicious attacks or has it been hardened sufficiently to make the plugin obsolete? Is there an alternative?
|
Yes it is still relevant, WordPress is very subject to query based attacks. It is more common and easier to attack bad plugins/themes, so even if your WordPress version is kept up to date, it's still a good idea. There is a better plugin called Mute Screamer, it uses a central PHPIDS database. http://wordpress.org/extend/plugins/mute-screamer/
|
Is the Block Bad Queries Plugin Still Relevant?
|
wordpress
|
is there a file where wordpress defines it's $GLOBALS? i'm just curious as to what wordpress uses it for and for what purpose. That's all!
|
I'm not sure if all of these are WordPress globals, but i did a quick grep type search of the WordPress files and tried to extract all the globals i could.. This is a list i compiled for you, that may not be perfect, but should *hopefully* represent alot of the <code> $GLOBALS </code> keys that WordPress uses, it won't account for globised variables that aren't explicitly defined as <code> $GLOBAL </code> , but still have global scope. <code> $GLOBALS['_menu_item_sort_prop'] $GLOBALS['_wp_sidebars_widgets'] $GLOBALS['blog_id'] $GLOBALS['body_id'] $GLOBALS['comment'] $GLOBALS['comment_depth'] $GLOBALS['content_width'] $GLOBALS['current_site'] $GLOBALS['current_user'] $GLOBALS['custom_background'] $GLOBALS['custom_image_header'] $GLOBALS['debug_bar'] $GLOBALS['editor_styles'] $GLOBALS['is_winIE'] $GLOBALS['link'] $GLOBALS['login_grace_period'] $GLOBALS['month'] $GLOBALS['month_abbrev'] $GLOBALS['more'] $GLOBALS['post'] $GLOBALS['post_type'] $GLOBALS['posts'] $GLOBALS['query_string'] $GLOBALS['request'] $GLOBALS['single'] $GLOBALS['submenu'] $GLOBALS['tab'] $GLOBALS['type'] $GLOBALS['weekday'] $GLOBALS['weekday_abbrev'] $GLOBALS['weekday_initial'] $GLOBALS['wp_admin_bar'] $GLOBALS['wp_filter'] $GLOBALS['wp_object_cache'] $GLOBALS['wp_post_types'] $GLOBALS['wp_query'] $GLOBALS['wp_styles'] $GLOBALS['wp_taxonomies'] $GLOBALS['wp_the_query'] $GLOBALS['wp_version'] </code> If you wanted to get a better idea of everything inside the global array you could run something like the following to get a print out, because the above approach was obviously flawed(globals are defined in more than one way). <code> add_action( 'shutdown', 'print_them_globals' ); function print_them_globals() { ksort( $GLOBALS ); echo '<ol>'; echo '<li>'. implode( '</li><li>', array_keys( $GLOBALS ) ) . '</li>'; echo '</ol>'; } </code> Which should give you a more comprehensive list of variables in the global scope.. Hope that's helpful.. :)
|
$GLOBALS array for wordpress
|
wordpress
|
I was just looking under my "Tools" menu in my WordPress site and noticed the "Export/Import" functions. I was not aware that this was even available and I've been needing it for some time. What version of WordPress did it originate with?
|
Exporting and Importing has been there since at least WordPress 2.1. Probably earlier. It moved into plugins with the release of 3.0, I believe.
|
In What WordPress Version Was the Import/Export Tool Introduced?
|
wordpress
|
Question has been asked before about how to synchronize files as well as the database between two Wordpress installations. For the database level, the answer is usually to basically dump one database and insert it onto another server. The problem with this is that you end up losing any changes that have potentially been made on the prod server. For instance, usage metrics, comments, etc... With this in mind, I was starting to wonder whether the it would be possible to extend the Wordpress ORM so that you can generate deltas and then inject those into the prod site. Has anyone tried this, looking into it, or have any ideas or comments ?
|
The reality is that what we want is this: http://www.liquibase.org/ Liquibase is an open source (Apache 2.0 Licensed), database-independent library for tracking, managing and applying database changes. It is built on a simple premise: All database changes are stored in a human readable yet trackable form and checked into source control. However our development process doesn't support it. We typically don't modify the database through discrete scripts we write ourselves, we use plugins that we activate. We don't write DML scripts to modify look-up data that we then check into source code control, we use a UI on the admin page and therefore have no source code for later use in replicating that change during migration. However, we can emulate some of it -- using some of the tools listed on this page: stackexchange-url ("stackexchange-url For instance, liquidbase has a diff feature that also, optionally includes changes to data. We could, potentially, output the schema and data diff to a script, excluding (as possible) certain tables likely to include test data ( i.e. post, etc. ) and then apply the script to the production database. MySQLDiff (discussed on the StackOverflow question) does schema diffs, and it's author recommends mysql_coldiff for table-wise data diffs - both are implemented in perl, if java tools (liquidbase) are too resource heavy for your servers -- although bring both databases local and running the tool on your PC solves that problem ... If we really want to do it right, we should log any sql that relates to settings, options, or other configuration changes, and any schema changes -- and convert the logged code into a migration script to play against our production server. Play the migration script against the server, copy the wordpress site files (excluding uploads, if applicable) and we're gold. So, it seems to me, that the best way out, is a developer's migration-builder-plugin that traps the sql we need, stores it and then generates a migration script from the logged code, rather than to build a way to merge databases between staging and production. Seems a simpler problem to solve too. If we look at the code of @bueltge 's instrumenting hook calls plugin for inspiration: https://gist.github.com/1000143 (thanks to Ron Rennick via G+ for pointing me in the direction of SAVEQUERIES and the shutdown hook, that lead me to find it) -- alter it to get the SAVEQUERIES output instead -- only run while in admin -- filter out all selects -- save results out to table in the shutdown hook -- we could selectively toggle output trapping based on what we were doing at the moment. For example: Capture Name: Activate & Configure Plugin XYZ Capture State Toggle - on ... install and configure plugin XYZ Capture State Toggle - off Export Migration Script for: Activate & Configure Plugin XYZ Press Export Button -- to produce a popup text field with the filtered trapped SQL - ideally pre-formatted as a shell script with command-line call to mysql. Copy & paste it out to your migration code folder and add to your source code repository. Careful attention to toggling the capture on and off as you're working and you'll be able to generate the perfect migration script to take your production database to an equivalent configuration to your staging database. What's better, you'll have a script (or series of same) that you can TEST. Imaging having replicable, testable, migration scripts!! I'm in love already. Anyone else?
|
Wordpress database synch between dev and prod
|
wordpress
|
I have the following code to do a foreach loop, I want to target the last item in the loop (e.g if it's looped over 3 events I want to target the 3rd event) to do something slightly different with the css. How would I do that? <code> <?php $pages = get_pages(array('child_of' => $post->ID, 'sort_column' => 'menu_order')); foreach($pages as $post) { setup_postdata($post); $fields = get_fields(); ?> <div class="event"> <img class="event-thumbimage" src="<?php echo $fields->thumb_image; ?>" height="120" width="140" alt="<?php echo $fields->event_title; ?>" /> <h2><?php echo $fields->event_title; ?></h2> <p> Location: <?php echo $fields->location; ?><br /> Start: <?php echo $fields->start_date; ?> at <?php echo $fields->start_time; ?> <?php $fields = get_acf(); if($fields->end_date != "") : ?> , End: <?php echo $fields->end_date; ?> at <?php echo $fields->end_time; ?> <?php else : ?> <?php endif; ?> </p> <p style="margin-bottom:0px!IMPORTANT;"><?php echo substr($fields->description,0,170) . "..."; ?></p> <p><a class="read-more" href="<?php echo get_page_link($post->ID); ?>" title="Read more about: <?php echo $fields->event_title; ?>">Read more...</a></p> </div> <?php } wp_reset_query(); ?> </code>
|
You can try this : <code> foreach( $pages as $key => $post ) </code> and : <code> <div class = "event <?php if( $key == ( count( $pages ) - 1 ) ) echo 'last'; ?>" > </code> It will add a <code> last </code> class to your last <code> event </code> div.
|
In a foreach loop, how do I target the last item in the loop?
|
wordpress
|
I have a CPT called "profile" that only supports the editor and thumbnail. Each user is limited to posting just 1 profile. I'm looking for a way to prefill the title and slug fields with the display name of the post author. As it is now, if I click on Publish, the post_status in the db is "Auto Draft" and the URL becomes "localhost/mytestsite/profile/auto-draft-1". It seems WP needs a title or else it won't be considered "Published". I've checked several questions already posted here and this one seems like the one I need. stackexchange-url ("Custom Post Type with Custom Title") But since I want the author's name and not values in a taxonomy or custom field, I don't know how to modify the code to reflect that. I see that get_the_author() needs to be in The Loop.
|
You could add a hidden input into the page to pre-set the title field, because it won't be on the page(because the type doesn't support titles). Slug is produced from the title, so you should only need add a title value. Something like this should work(though untested).. <code> add_action( 'submitpost_box', 'hidden_type_title' ); function hidden_type_title() { global $current_user, $post, $post_type; // If the current type supports the title, nothing to done, return if( post_type_supports( $post_type, 'title' ) ) return; ?> <input type="hidden" name="post_title"value="<?php echo esc_attr( htmlspecialchars( get_the_author_meta( 'display_name', $current_user->data->ID ) ) ); ?>" id="title" /> <?php } </code> Though i'd perhaps suggest adding further to the code and checking if the author display name is not empty, etc... it should be enough to work with..(or get you started at least).. :)
|
Setting a title on a Custom Post Type that doesn't support titles
|
wordpress
|
I have a shortcode function that returns: <code> return '<ul class="list-pages">'. wp_list_pages( $args ) .'</ul>'; </code> Of course it returns: <code> {pages} <ul class="list-pages"></ul> </code> Instead of: <code> <ul class="list-pages"> {pages} </ul> </code> There is almost the same question, but for echo: stackexchange-url ("Why does this echo values in the wrong order?") And it works perfectly for echo, but I don't know how to use PHP line breaking with "return" (it breaks the whole code). Thank you!
|
it is b/c wp_list_pages ECHOES by default. so it echoes before your return happens. wherever you are defining your $args, set 'echo' => FALSE, see http://codex.wordpress.org/Function_Reference/wp_list_pages
|
Shortcode returns values in the wrong order
|
wordpress
|
I've deleted my previous question as it was migrated from Prowebmaster to WordPress section, and hence it was deep down somewhere. I'm in a quandary about using SEO Plugin for my WordPress site. Here's the thing: I was a happy camper with the Yoast SEO Plugin but because I couldn't edit Meta Description in bulk, stackexchange-url ("I reached out for help in this forum"). One of the nicest guy recommended me to use SEO Ultimate Plugin. To me, this plugin works very well. Plugin is excellent. Plus, more importantly, I can edit Meta Description without sweating bullets. Now, Yoast SEO Plugin is configured such that it strips category URLs, modifies archive pages with the /date extension and so on. Also it strips away a lot of unnecessary codes from the WordPress core structure -- the WP version, Rel Next, Prev links, etc. SEO Ultimate, on the other hand, will be used primarily to edit Meta Description. However, Yoast SEO Plugin, by default, shows up Title and Meta Description. So I have two MD and I can't switch off Yoast SEO Plugin -- no tick box to switch off the MD. I need your advice. What do I do? I want to kill Yoast SEO Plugin's MD but I don't know how. I want to keep using SEO Ultimate but -- damn! -- I can't do it because of this issue. Any help is highly appreciated.
|
Throw this into your functions.php: <code> function clear_yoast_metadesc( $metadesc ) { return ''; } add_filter( 'wpseo_metadesc', 'clear_yoast_metadesc', 99, 1 ); </code> If you set the <code> $metadesc </code> to empty like that, it won't be echoed. BTW, bulk editing is very hard on my to-do list, so you would be able to switch back completely :)
|
Help in using SEO Plugins: SEO Ultimate And Yoast SEO Plugin
|
wordpress
|
Now i face a problem, that i want to add a hook into the the_post. Then i use <code> print_r($post); </code> here display the my <code> print_r </code> content and again display the default content. because i am here in the_loop.so again the content was display. <code> add_action( 'the_content', 'custom_post' ); function custom_post() { global $post, $wp_query; $post_id = $post->ID; print_r($post); } </code> Here i need how to overwrite the default content of the the_post and display my own content. This is possible in a way, that i use the_title and the_content hook but here the function was call two times then its problem. so plz help me.
|
Take a look at my answer here, if you are trying to replace the post content: stackexchange-url ("Edit the_content function")
|
Wordpress add_action the_post hook
|
wordpress
|
I am trying to install Wordpress on WAMP I changed my localhost path to <code> localhost:11245 </code> in the WAMP config file, so when I load my apache admin screen I go to <code> localhost:11245 </code> When I loaded Wordpress, <code> localhost:11245/wordpress </code> , it prompted me to enter the admin information, that is what I entered : Database Name : <code> wordpress </code> User Name : <code> wpadmin </code> Password : <code> blank </code> Database Host : <code> localhost:11245 </code> Table prefix : <code> wp_ </code> When I click <code> Submit </code> , it loads indefinitely. Somehow I made it come up with the following error. I imagine this has something to do with me changing the port number. Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding. Database name Database username Database password Database host Table prefix (if you want to run more than one WordPress in a single database) If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php. In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you’re all ready… How can I get it to install? EDIT I was able to get WAMP to route to <code> localhost </code> , then I ran <code> localhost/wordpress </code> and went through the setup screen again with these settings : Database Name : <code> wordpress </code> User Name : <code> root </code> Password : `` Database Host : <code> localhost </code> Table prefix : <code> wp_ </code> I just ran a php page with this info on it and it returned <code> Connection OK </code> <code> <?php $link = mysql_connect('localhost','root',''); if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); } echo 'Connection OK'; mysql_close($link); ?> </code>
|
here are the instructions i followed: http://webdesignerwall.com/tutorials/installing-wordpress-locally
|
WAMP Wordpress installation cannot get past step 1, loads indefinitely
|
wordpress
|
For example: <code> http://www.example.com/dell/studio/studio-1558 </code> where <code> dell </code> and <code> studio </code> are categories A few months back I heard from someone that it is not possible. I need to know why? Which part of code prevents it? Is there any workaround for this?
|
Some folks asked the same question you did here. stackexchange-url ("This one") specifically worth reading, if you haven't already. It has ottopress explanation for harmful permalinks. If you really want to force this, you could write your own permalink (http://domain.com/category/subcategory/post...), then either use htaccess rewrite rule or WP_Rewrite to take them to the link wordpress generated. This merely satisfies your visual requirement, but it adds server load.
|
Specifying multiple categories in URL (permalink)?
|
wordpress
|
So here is the thing. I'm creating a site. A user can register in my site and post articles. The thing is I don't want separate admin area to post articles. I want to integrate everything in my theme. So the user don't need to go to wp-admin to create posts. I'm using magic fields plugin. I created a custom write panel. Now my only problem is i don't know what shortcode or hook i should use to display that custom write panel in my theme. I mean i want the whole write panel in my theme. Here is a sample snapshot of custom write panel. I want to display the whole custom panel in my frontend. So logged in users can submit articles from that page. I hope you guys get what i mean. Thanks
|
I'm afraid it won't work quite like that. There are plugins that enable posting from the front end, such as TDO Mini Forms . Or stackexchange-url ("see this answer") for creating a form and code yourself.
|
How to display magic field's custom write panel in wordpress theme?
|
wordpress
|
Here is an example Cat 1 has 6 post: ( post 1 , post 2 , post 3, post 4 etc.. ) Cat 2 has 6 post: ( post 1 , post 2 , post 3, post 4 etc.. ) i want to display random post like this: Today's CAT 1 Random post : Post 2 Today's CAT 2 Random Post : Post 5 but the posts has to change per 24 hours. Is it possible. Thanks ( Sorry about my bad Eng )
|
You could always use get_posts() to return a random post, but it would change every time the page loaded. So, here's an idea for you. In a plugin file, set up a wp_cron hook. <code> <?php /* Your plugin header goes here */ register_activation_hook( __FILE__, 'wpse24234_activation' ); function wpseo24234_activation() { wp_schedule_event( time(), 'daily', 'wpse24234_daily' ); } </code> Then hook a function into your cron action that grabs a random post (via get_posts()) and stores it in a transient that expires every 24 hours. <code> add_action( 'wpse24234_daily', 'wpse24234_daily_cb' ); function wpse24234_daily_cb() { $posts = get_posts( array( 'cat' => YOUR_CATEGORY_ID_HERE, 'numberposts' => 1, 'orderby' => 'rand' ) ); if( ! empty( $posts ) ) set_transient( 'cat_1_post', $posts[0]->ID, 60 * 60 * 12 ); } </code> Then on the front end, you can get the post ID with get transient, and use the ID to pull in whatever other stuff you'd like. <code> <?php /* Somewhere on your site */ $id = get_transient( 'cat_1_post' ); $link = '<a href="' . get_permalink( $id ) . '">' . get_the_title( $id ) . '</a>'; ?> Todays random post from Category 1 is <?php echo $link; ?> </code> You'll have to do some testing to see if this will work for you, of course.
|
How to display Changing post link for 24 hours in x category
|
wordpress
|
Update: I managed to get the AJAX working, but not in the click event. I updated the question to match this. I'm trying some code I found on the page: 'AJAX in Plugins' . However I can't get it to work, and I Don't really know where to start looking. It works when I remove the click function and just run the code on pageload. I have a Javascript file that looks ike this: <code> jQuery(document).ready(function(){ jQuery("#createremotesafe").click(function(){ alert ('test'); var data = { action: 'my_action', whatever: 1234 }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php jQuery.post(ajaxurl, data, function(response) { alert('Got this from the server: ' + response); }); }); }); </code> and somewhere in my PHP script that generates the button that should execute the Javascript (i.e. the admin page), and also the rest of the page: <code> add_action('wp_ajax_my_action', 'my_action_callback'); echo 'test2'; function my_action_callback() { global $wpdb; // this is how you get access to the database $whatever = $_POST['whatever']; $whatever += 10; echo $whatever; die(); // this is required to return a proper result } </code> I get both the <code> Alert ('test') </code> and the <code> echo 'test2' </code> , but not the response alert. There are no Javascript errors or anything. My code is definitely running, since I can see both 'test's, but why isn't AJAX getting any response? Does my php function disappear after page load? Maybe I can't/shouldn't use the built in wp AJAX functions? It also doesn't show an empty alert box, just nothing happens.
|
Start from a working code base.. <code> add_action('in_admin_header', 'my_ajax_button'); function my_ajax_button() { echo '<a href="#ajaxthing" class="myajax">Test</a>'; } add_action('admin_head', 'my_action_javascript'); function my_action_javascript() { ?> <script type="text/javascript" > jQuery(document).ready(function($) { $('.myajax').click(function(){ var data = { action: 'my_action', whatever: 1234 }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php $.post(ajaxurl, data, function(response) { alert('Got this from the server: ' + response); }); }); }); </script> <?php } add_action('wp_ajax_my_action', 'my_action_callback'); function my_action_callback() { global $wpdb; // this is how you get access to the database $whatever = $_POST['whatever']; $whatever += 10; echo $whatever; exit(); // this is required to return a proper result & exit is faster than die(); } </code> That's the code(with a minor adjustment) from the codex page, and that's perfectly fine for me, so i'd suggest using that as a starting point.. if that's what you initially did, at what point did it break or stop working? NOTE: Mark is me, i use a secondary account when accessing the site from another PC(that isn't mine).
|
How can I run AJAX on a button click event?
|
wordpress
|
Can I change the name of the wp-login or wp-admin file so that I can go to a different filename in order to login. I am trying to prevent hackers from finding my login and wp-login has become a very obvious option.
|
As far as i know you cannot rename wp-admin. Many themes and plugin uses wp-admin in path. So if you rename it then all your plugins and themes will be broken. If you don't want your users to access wp-admin then restrict it using .htacess If anyone access your wp-admin url redirect them to other page using .htaccess file. Only allow certain IPs to access wp-admin. For example use this .htaccess code in your root of wp-admin (Not your wordpress root). Create a new .htaccess file there and use this code. <code> AuthUserFile /dev/null AuthGroupFile /dev/null AuthName "Example Access Control" AuthType Basic <LIMIT GET> order deny,allow deny from all allow from xx.xx.xx.xx allow from xx.xx.xxx.xx </LIMIT> </code> Replace xx.xx.xx.xx with your IP address. You can add more. Thereafter only you can access wp-admin. You can also use redirection plugin. If you must want to rename wp-admin then proceed to read more but with extreme caution. Just replace "wp-admin" with your keyword. Use this simple search and replace tool. Here is the screenshot of that tool. Warning: If you update your wordpress then your site will be broken. You should replace them in themes and plugins too. I highly NOT recommend this option. Use this option only if its mandatory. I'm not responsible for any problem that arises if you use this option.
|
Change WP-Login or WP-Admin
|
wordpress
|
I need to add a bit of document ready jQuery to post/page editors in admin. I'm hacking an old plugin that adds a text box to the editor page and handles inserting that text in a template file, but the text input is only html; this document ready function adds the class of mceEditor to the text box. This function works when I manually include it in admin-header.php, but I can't do that, of course. I don't think I need to enqueue it, as it is not a library. Or do I? And, if applicable: what are the pros/cons of different ways to add it? So how do I hook this or otherwise load it into the post/page editors in admin? It needs to go into the plugin file, not functions.php in the theme. <code> <script type="text/javascript"> jQuery(document).ready( function () { jQuery("#dt-additional-info").addClass("mceEditor"); if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) { jQuery("#dt-additional-info").wrap( "<div id='editorcontainer'></div>" ); tinyMCE.execCommand("mceAddControl", false, "dt-additional-info"); } }); </script> </code>
|
I'd be inclined to just do a one off enqueue and be done with it.. It means you have to manage an additional file(the JS file), but when you're writing code it's usually a good idea to create some form of organisation with your files(or at least get into the habit of doing so), ie. javascript/jquery in one folder, css is another, keeping PHP and HTML in your main plugin PHP files. So my suggestion would be to move the jQuery into a js file, then run an enqueue setting jQuery as a dependancy, but no need to register it for a one off call. Quite a few choices with regard to hooks, but i'd personally go for.. <code> function yournamespace_enqueue_scripts( $hook ) { if( !in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) return; wp_enqueue_script( 'your_script_handle', // Handle plugins_url( '/yourfilename.js', __FILE__ ), // Path to file array( 'jquery' ) // Dependancies ); } add_action( 'admin_enqueue_scripts', 'yournamespace_enqueue_scripts', 2000 ); </code> Simply adjust the pages you need the enqueue to run on - in the <code> in_array() </code> call.
|
Add a jQuery function to admin pages
|
wordpress
|
I'm trying to display wide image icons from the_post_thumbnail() function. I'm using 'true' value for cropping, but they are not cropped well... I get some strange results with different sizes (I'm trying to use 200width x 150height). If image cannot be display with good proportions (I don't know why whem I'm cropping it? ) then I want it to have exact 150px height always! How can I achieve it? I've been trying with set_post_thumbnail_size() but its even worst...
|
If the critical dimension is height, you have a couple options: Hard-cropping to the exact width/height: <code> <?php add_image_size( 'wide-image-icon', 200, 150, true ); ?> </code> The hard-crop will create a thumbnail size using the exact dimensions. Be sure that all images have a minimum width/height as what is defined. Or soft-cropping (i.e. "box-resizing") constrained to height: <code> <?php add_image_size( 'wide-image-icon', 9999, 150, false ); ?> </code> The soft-crop with an unconstrained dimension (i.e. <code> 9999 </code> width) will box-resize to the exact height , while allowing the width to be, essentially, anything. Be sure that all images have a minimum height as what is defined. Also: make sure that, if you have added these <code> add_image_size() </code> functions after already uploading/attaching some images, that you regenerate your thumbnails .
|
the_post_thumbnail() Custom sizes not display correctly
|
wordpress
|
I think thats what its called... Basically a conditional statement if there are any posts in a specific custom post type/custom taxonomy, show posts, it not show an img or include whatever…? But cycle through a few custom post types? Checking in each if there is a post in the featured custom tax and if not skip on to the next one, ending up if a temp image or something... So a conditional tag with query i suppose… <code> if <?php $loop = new WP_Query( array( 'post_type' => 'profile','profile-type' => 'featured','posts_per_page' => '-1' ) ); ?> show post details else if <?php $loop = new WP_Query( array( 'post_type' => 'films','film-type' => 'featured','posts_per_page' => '-1' ) ); ?> show post details etc etc else show include or temp image </code> Can it be done, or asking a bit too much of the technology? Many thanks for any help :)
|
You can use the <code> have_posts </code> function. For more information, visit The Loop <code> <?php $loop1 = new WP_Query( array( 'post_type' => 'profile', 'profile-type' => 'featured', 'posts_per_page' => '-1' ) ); $loop2 = new WP_Query( array( 'post_type' => 'films', 'film-type' => 'featured', 'posts_per_page' => '-1' ) ); if($loop1->have_posts()) { while($loop1->have_posts()) { $loop1->the_post(); // content here } } elseif($loop2->have_posts()) { while($loop1->have_posts()) { $loop1->the_post(); // content here } } else { // content if all else fails } ?> </code>
|
Conditional Tag Custom Querys?
|
wordpress
|
If I change my permalink structure, is there is a nice way to handle when people/bots go to the old structure? I presume I can add use .htaccess and write a rule to redirect based on a 301 but is it possible in my case? I currently have site.com/%year%/%month%/%day%/%postname% and I will just want site.com/%category%/%postname%
|
Dean's Permalink Migration has always worked for me. Install it before you change your permalinks.
|
Nicest way to 301 Redirect traffic when changing permalink settings
|
wordpress
|
I am using the theme-options.php file from ThemeShaper: http://themeshaper.com/2010/06/03/sample-theme-options/ I can succesfully add new dropdown options, however when I add a new text input I receieve this error when I view it in the admin area (I added the THEME_DIRECTORY): <code> <br /> <b>Notice</b>: Undefined index: cpt_sm_dribbble_handle in <b>/[THEME_DIRECTORY]/theme-options.php</b> on line <b>359</b><br /> </code> When I change the input value to something else and save it, it works fine and never gives an error again. However I don't want this error message to appear to users. I would rather it just appear blank since there is no value inputted yet. I suspect that I'm getting this error because the database doesn't recognize this new option. And I think I need some sort of verification in my code to say if this doesn't exist set the value to null. Though I'm not sure if this really is the problem and if so how to fix it. Here's the minimized code for my options file and for a new text option (I've noted the line that is throwing the error): <code> add_action('admin_init', 'cpt_options_init'); add_action('admin_menu', 'theme_options_add_page'); function cpt_options_init() { register_setting('cpt_options', 'cpt_theme_options', 'theme_options_validate'); } function theme_options_add_page() { add_theme_page('Theme Options', 'Theme Options', 'edit_theme_options', 'theme_options', 'theme_options_do_page'); } function theme_options_do_page() { global $sm_select_options; if (!isset($_REQUEST['settings-updated'])) $_REQUEST['settings-updated'] = false; ?> <form method="post" action="options.php"> <?php settings_fields('cpt_options'); ?> <?php $options = get_option('cpt_theme_options'); ?> <tr valign="top"> <th scope="row">Dribbble</th> <td> <label class="description" for="cpt_theme_options[cpt_sm_dribbble_handle]">Dribbble Username</label> <input id="cpt_theme_options[cpt_sm_dribbble_handle]" class="regular-text" type="text" name="cpt_theme_options[cpt_sm_dribbble_handle]" value="<?php esc_attr_e($options['cpt_sm_dribbble_handle']); ?>" /> // THIS IS THE LINE THAT IS THROWING THE ERROR (line 359) </td> </tr> </form> <?php } function theme_options_validate($input) { global $sm_select_options; // Say our text option must be safe text with no HTML tags $input['cpt_sm_dribbble_feed'] = wp_filter_nohtml_kses($input['cpt_sm_dribbble_feed']); return $input; } </code> Any ideas on what I'm doing wrong? Thanks for your time.
|
Wrap the call in an <code> isset() </code> conditional in this line: <code> <input id="cpt_theme_options[cpt_sm_dribbble_handle]" class="regular-text" type="text" name="cpt_theme_options[cpt_sm_dribbble_handle]" value="<?php esc_attr_e($options['cpt_sm_dribbble_handle']); ?>" /> </code> Try something like this: <code> $cpt_sm_dribbble_handle = ( isset( $options['cpt_sm_dribbble_handle']) ? $options['cpt_sm_dribbble_handle']) : '' ); <input id="cpt_theme_options[cpt_sm_dribbble_handle]" class="regular-text" type="text" name="cpt_theme_options[cpt_sm_dribbble_handle]" value="<?php esc_attr_e($cpt_sm_dribbble_handle); ?>" /> </code> EDIT Note: your other alternative is to set default options on init, so that this option is set to some default value, e.g. an empty string.
|
New custom theme option (text input) giving index error
|
wordpress
|
I want to make the following happen in Wordpress People answer questions in paginated or single page form. Each next set of options is dependent on the option the user selects preiviously At the end, the user is directed to a page which is a common ending for all questionnaire trees. All this questionnaire options can be viewed/exported Question: How can this be done? or if there is a plugin available for a similar purpose? If not wordpress, is there another CMS that offers this?
|
This plugin is capable of doing exactly what you are after http://www.gravityforms.com/
|
Non-Linear Questionnaires in Wordpress
|
wordpress
|
Sorry for the simple question. I've published a page. Let's say that I now need to make changes to the page. Can I simply edit it, after it's been published? Or should I use a maintnenace mode? If someone tries to view the page at the same time that I'm editing it, will they be greeted by an error message? Thank you. -Laxmidi
|
You can edit the page at any time after it is published. I would not recommend using maintenance mode, as then your entire site will be unavailable while you are editing the page. When you are editing, your site is unaffected until you click "Update" and save the changes to the published post. No users will receive error messages when you edit, however they may see the old content until they refresh.
|
Editing Pages that Have Already Been Published
|
wordpress
|
My goal is to return posts based on a specific price range using <code> meta_query </code> . The price in the admin that the user enters is a custom field, created using WPAlchemy . In the example below, the query would return any posts with a price value between 1000 and 1500: <code> 'meta_query' => array( array( 'key' => '_my_price', 'value' => array( 1000, 1500 ), 'type' => 'numerical', 'compare' => 'BETWEEN', )), </code> It works fine if a price value was entered as <code> 1200 </code> (and stored as 1200 in the DB), but how could I get this working for prices that are stored in the database that have dollar signs and commas such as <code> $1,200 </code> ? Ideally I would like all price values on the website to be consistent, so I'm using a Javascript currency formatter that converts the prices, which is why I'm asking. If a user enters 1200, it converts it to <code> $1,200 </code> , which is then stored in the database. The meta_query doesn't think this is a number and therefore returns no results. Or maybe there's a better method. Would it be better to ditch the JS formatter on the input fields in the admin and instead add the dollar sign and comma separation on the front end? This seems more logical, but then it raises another question of how to prevent a user entering a dollar sign or comma formatting in the admin.
|
Would it be better to ditch the JS formatter on the input fields in the admin and instead add the dollar sign and comma separation on the front end? Yes, definitely. This seems more logical, but then it raises another question of how to prevent a user entering a dollar sign or comma formatting in the admin. Sanitize the input before storing it, using <code> absint() </code> .
|
How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
|
wordpress
|
I've a strange problem with an Autofocus theme. In my templates file, header.php, I've a code like this (and is correct) <code> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> </code> When I look at the source code of the generated HTML, I found something like this <code> [blank] [blank] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> </code> The extra blank lines are breaking my RSS feeds... Other info: No filters on the content except wpautop functions.php doesn't do anything on the content Plugins All In One Seo, WP Stats, Smiley Remover, SEO Friendly images Any clues?
|
<code> the_content </code> doesn't affect the <code> DOCTYPE </code> and <code> <html> </code> tags, only the post/page content. One of your plugins, or something else in the theme is either throwing an error, or is printing something earlier than it should. Have you tried: Disabling each plugin one by one and see when it is fixed. Editing wp-config.php and adding <code> define( 'WP_DEBUG', true ); </code> to look for errors
|
Unwanted blank lines before tag
|
wordpress
|
I'm using <code> get_terms </code> to output a taxonomy's terms, which are all numbers: For example: 4, 6, 8, 10, 12 How can I order these numerically, so they appear exactly as above? What I'm getting is actually: 10, 12, 4, 6, 8 I can see why it's done this (thinks 10 is first because it starts with a 1) but how can I fix it? I've tried all the ordering options on the codex for <code> get_terms </code> but can't seem to get them in order. Here's an example of what I have so far. I've even tried ordering by id and entering them in order but it still muddled it up. $taxonomy_array = get_terms('taxonomy-name', 'hide_empty=0');
|
I have a plugin, Custom Taxonomy Sort , that allows you to sort taxonomy terms in any order that you might want. After installing the plugin, there will be an order field for each term. It will save these values as integers and will properly sort your taxonomy terms. By default, it will use the order you specify to sort the terms. It also enables a new value for sort the <code> orderby </code> parameter, "custom_sort". You would be able to do something like: <code> <?php $terms = get_terms('taxonomy', 'orderby=custom_sort'); ?> </code>
|
How to order a taxonomy's terms numerically, from lowest to highest using get_terms
|
wordpress
|
I'm looking into a way to have global menus across my network of blogs. Basically I am using wordpress as a CMS - the purpose of the network is actually to ringfence content. The sub blogs will be able to customise some areas of the template - but I would like them to share the main site's menu system. This is easy enough for a static consistant menu - but my clients would like to be able to make changes to the menu on the main, top-level site using wordpress' built in custom menu system. So - in short, can my sub sites in a blog network show the custom menu from my top level site? Thanks
|
Try this plugin Network Wide Menu by Ron Rennick . It does exactly what it says: "Implements a network wide menu using a menu in the main site of your network". I tested in WPMU 3.3.1 and it works. Network Activate the plugin or drop the script "ra-network-wide-menu.php" directly in the /mu-plugins/ folder. Follow the tutorial from the plugin page.
|
global menus made from master site's custom menus wpmu network
|
wordpress
|
My site as of right now is a static website. I am planning on having a 'recent blog posts' section on it, with permalink to the main blog post/blog. example: <code> http://site.com/blog </code> I was wondering, because of having a recent blog posts section on the homepage, should I just have the entire website powered by WordPress and just add the homepage (and other pages, such as contact) as a word press 'page', and call recent blog posts on it? If I do it that way, am I still able to have the blog in <code> /blog </code> ? I was also thinking of just adding the whole WordPress files to the /blog directory and call recent blog posts from the static file... I am new to Wordpress, so I am a bit confessed here. What is the best option?
|
You can do either, it's up to you depending on how invested in your static site you are and how much work you want to do transferring things over. The Codex page on Integrating WordPress with your website outlines how you could have WordPress installed in the /blog directory, and show recent posts on your static site through the use of a bit of php. Your other option is to have WordPress take over serving all of your site's content. It's pretty easy to set up a static home page, plus contact, etc., as well as a blog at whatever url you choose. See the Codex page on WordPress Settings > Reading . You just need to create two pages, then designate one your home page and the other to be the page that shows your posts.
|
How should I best incorporate WordPress in my static website?
|
wordpress
|
I'm building a WP 3.2 site with a couple of custom post types and taxonomies. I'm calling one of these custom post types programs , and its associated taxonomy is called topics . I'd like to add an item called "Topics" in the site's horizontal navigation, with a dropdown submenu that lists all categories in the topics taxonomy. Each submenu item would then link to its respective category archive page. Is this possible? I assumed this would be pretty easy in WordPress, but I've been searching around for a while to no avail. EDIT: This blog post and plugin come close, but it seems to only apply to blog categories (that is, I don't see how to adapt it for a custom taxonomy).
|
This is enabled by default if your using <code> wp_nav_menu </code> ( the drag & drop menu's in admin) and have also set <code> show_in_nav_menus </code> to true for your <code> register_taxonomy </code> . To enable them to show go to Admin--> Appearance--> Menus Click "Screen Options" in the top right and you should see it listed there. ps. The post you linked is obsolete.
|
Can I output a custom taxonomy as a submenu in the site navigation menu?
|
wordpress
|
I am tempted to change my blog to be site.com/postname. I know that for new posts Wordpress is smart enough to add a unique number to them, but what about old posts that would get updated? I can run a database check for duplicates and manually fix them but I was wondering if this was already covered by some Wordpress magic?
|
Any time you have a duplicate slug for a post or taxonomy, WordPress just adds '-2' to the end of the slug.
|
If the only permalink setting is %postname% what happens in the case of old duplicates?
|
wordpress
|
I have a client who wants to have online application forms for their non profit service. I have used Contact Form 7 in the past, since its pretty flexible and you can have lots of fields, radio buttons etc which I LOVE. The only concern is that just sends a plain text email, they want a way that they can save the data into a spreadsheet or database of some sort. Weither it attaches a xml to an email when the form is filled, or it saves it in the admin where you can then export it. Is there anything out there like this? OR is there even a way to have a PDF online where people can type in it, fill it in then email it off? Since all the documents are in PDF form already this would be even easier.
|
The Contact Form 7 to Database Extension plugin will save the form data to the database. I haven't used it myself, so don't know whether it offers easy ways of then extracting it, or if you have to deal with extracting it yourself.
|
Detailed form plugin, with ability to export to excel etc. OR edit PDF live?
|
wordpress
|
I'm writing a custom signup script for users to register with on my MU-setup. One problem I'm having is that <code> wpmu_signup_user() </code> sends the password activation email but it doesn't return the user ID which I need for the rest of the script. - It's my understanding that this doesn't create the user account, just an entry in the "signup" table. The other way I've tried is using <code> wp_create_user() </code> which returns the user ID I need (as it creates the user properly) but no email for the user.
|
If you want to force add a MU user and activate them, and email them, this will do it. It's a slightly altered version of a piece of the code in user-new.php. <code> wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $blogid, 'new_role' => $role ) ); $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) ); $ret = wpmu_activate_signup( $key ); </code> The wpmu_activate_signup function will send the welcome email. And the $ret from wpmu_activate_signup is an array of several things, including the user_id in $ret['user_id']. Obviously you'll need to fill in the user name, email, blogid, and role in the above code.
|
Need to manually regsiter user, send the password and retreive their user ID
|
wordpress
|
Now I've never really used Wordpress with more than one author and it's usually been myself so I've followed no editorial process, but with my new site, I'm looking to add a handful of users to the Author role. I understand there's many roles with different permissions within Wordpress already, but I can't seem to find whether or not there's an option or any documentation about setting WP up so that when Authors submit an article it should go to the Editor group for approval before anything gets published (editors are notified of new pending items via e-mail). Is this possible? Or does it work like this by default? As I don't know, I thought I'd ask here. Thanks for any help in advance
|
Yes that's the default behavior. When an "author" writes a post, he cannot publish it, only an "editor" (or higher) can do the publishing action. As for email notification, there are a couple of plugins for that, here are two : WP Status Notifier WP Pending Post Notifier
|
Editorial Process
|
wordpress
|
I want to edit the default function <code> the_content() </code> . I know i can <code> add_filter('the_content', 'with_my_function') </code> but im having trouble outputting the old content with mine. Heres an example of what im doing. <code> add_filter('the_content', 'my_function'); function my_function() { $write = 'hello world'; $content = apply_filters('the_content', get_the_content()); echo $write.$content; } </code> How can i get this to work?
|
Not exactly sure what you are trying to accomplish, but it looks like you are trying to prepend something to the beginning of the_content. Try this: <code> add_filter('the_content', 'se24265_my_function'); function se24265_my_function( $content ) { $write = 'hello world'; $new_content = $write . $content; return $new_content; } </code> Most filters will provide a parameter or two for your function to manipulate and then return.
|
Edit the_content function
|
wordpress
|
Can anyone help me filter wp_get_attachment_link so that a particular occurence of it links to the 'medium' or other size image rather than the full size. I have the following in a page template: <code> $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { echo wp_get_attachment_link( $attachment->ID , array(150,150) ); } } </code> I can add a filter to add class or rel but I can't find anyway to alter the default (as originally uploaded) full size image linked to in the template .... The above works fine with colorbox (not plugin) to create a lightbox, but if a user uploads a very large image (ie: 4000x4000+ pixels), the link will load too slowly and I don't want the public to be able to download a print quality image from the lightbox..
|
I think I've answered my own question sort of.... As I was using a child theme of Hybrid I activated the cleaner gallery extension in the functions.php file: <code> add_theme_support( 'cleaner-gallery' ); </code> Then, based on the topic here I created my own filter: <code> add_filter( 'cleaner_gallery_image', 'my_gallery_image', 10, 4 ); function my_gallery_image( $image, $id, $attr, $instance ) { $post = get_post( $id ); $image_src = wp_get_attachment_image_src( $post->ID, 'medium' ); $image_thumb = wp_get_attachment_image_src( $post->ID, 'Custom Thumb' ); $title = esc_attr( $post->post_title ); $image = "<a href='{$image_src[0]}'><img src='{$image_thumb[0]}' border='0'></a>"; return $image; } </code> There are still things that are not right such as the title, but it answers the original question, though I'm sure it could be improved on as I'm rather going by the seat of my pants....
|
Change image link: wp_get_attachment_link
|
wordpress
|
I'm using wordpress 3.0 with buddypress. I need to enlarge the file size that is being uploaded from the media section in the admin menu. We have tried many ways including the methods from this link but nothing made it larger than a 1 mega. Is there a different way to do it? Thanks
|
If you are using multisite make sure you set "Max upload file size" to some higher limit. Network Admin -> Settings -> Network settings -> Upload settings -> Max upload file size
|
How to enlarge the media file upload size in wordpress admin
|
wordpress
|
So, I was thinking I'd use WordPress' Bookmarks/Links content type to populate a slider... ...Except there are a grand total of four functions interacting with this part of WordPress. I don't think you can even access these with a WP_Query object, and it seems all date-related data attached to these is in relation to the last update of the link itself (I.e., when the linked-to page is updated). Is there any way to even retrieve only the most recently-added bookmark? (For more of a semi-related discussion question for the comments -- if this aspect of WP is so woefully underdeveloped 3 versions of the CMS in, why not just farm out this functionality to a plugin? Simply backwards compatibility?)
|
As far as I know it's not possible to query the links directly, but there is definetly a <code> link_updated </code> field in the wp_links table, so you can use <code> wpdb </code> to interact with it and return the latest (modified) links. There's also a solution stackexchange-url ("here"). EDIT : Updating a link doesn't change <code> link_updated </code> , but here is a plugin that can solve that : Link Updated Plugin Auttomatically update the link_updated field when adding or editing a link, so you can use Links as a linklist. EDIT 2 : If using the Links/Bookmarks functionality is too much of a hassle, as it seems it's really not as flexible as posts, you could also create a custom post type or a post format for Bookmarks and work with that.
|
Getting only the most recent bookmark?
|
wordpress
|
Did I use custom enough in the title? Here is a quick explanation of what I am doing. I am creating a genealogy site and I have a custom post type called "Ancestor" In this post type there is quite a bit of information that is going into custom fields. To make it more user friendly, I've created a few custom meta boxes to organize the data. None of the fields in those meta boxes need to be unique. No one will have more than one birth date, etc. But the next custom meta box I need to tackle is the "Parents / Siblings" box. I don't want to create a meta box with 15 custom fields IDed as sibling1, sibling2... I'd like to make use of the "Add Custom Field" button that lets you dynamically add additional custom fields. So people could add as many or as few sibling fields as they need. I've created the meta boxes using the method at http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html Any info or shove in the right direction to adding a "New Sibling Field" button would be greatly appreciated.
|
I suggest to use WP Alchemy Metabox . What you are looking for is the have_fields_and_multi .
|
Adding a custom "Add Custom Field" button to Custom Meta boxes
|
wordpress
|
I'm trying to create a settings page. If I print things within index, I can see it. If I try to include it, I can't see anything, neither errors. <code> add_options_page('My Plugin', 'My Plugin', 'manage_options', 'my-plugin', array('MyPluginSettings', 'index')); </code> my settings: <code> class MyPluginSettings { public function index() { /* I can echo or print here and it works fine ... * But i can't require a file here ... nothing happens */ require('existing/path/to/a/file.php'); } } ?> </code> What's wrong? Thanks.
|
Most likely the file cannot be found, I'm assuming the file you're trying to include is located in your theme folder, in that case you should use: <code> require_once( TEMPLATEPATH . '/file.php'); </code> <code> TEMPLATEPATH </code> will return something like this: <code> /home/user/httdocs/wp-content/themes/twentyeleven </code> . Worst case scenario you'll find a Fatal Error , but that'll help to find the problem.
|
I cannot include a file in my plugin settings page
|
wordpress
|
I am trying to add a stylesheet when users are accessing the blog section of my site from and iPad. The first snippet of code works, however, I don't want to use the absolute path. I want to use wordpress's function. <code> function ipad_css() { if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT'])) {?> <link rel="stylesheet" type="text/css" href="http://website/wp-content/themes/my_theme/ipad.css" media="screen" /> <?php } } add_action('init','ipad_css'); </code> This doesn't seem to work: <code> function ipad_css() { if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT'])) {?> <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/ipad.css" media="screen" /> <?php } } add_action('init','ipad_css'); </code> I'm confused as to why it won't work. I have trying <code> stylesheet_url </code> as well with no luck.
|
Try replacing <code> <?php bloginfo('template_directory'); ?> </code> with <code> <?php echo get_template_directory_uri(); ?> </code> Also, I wouldn't hook it to the <code> init </code> action, why don't use <code> wp_print_styles </code> instead? It is a style after all.
|
Alternate stylesheet only works with absolute address for link?
|
wordpress
|
For the past two weeks I've been looking for a way to create a query in wordpress that returns all custom post types where a meta_key "mytype-expired" is NOT set to "yes" and then order the results by a second meta_key called "mytype-sort-order" with the highest number value coming first. If no value exists in the "mytype-sort-order" meta_key field, I want these posts to be displayed order by date (most recently added first), and all of these should be below posts that do have a value. For example, these set of test posts : Post 1 (from July 1st, mytype-sort-order value not set), Post 2 (from July 2nd, mytype-sort-order value not set), Post 3 (from July 3rd, mytype-sort-order value not set), Post 4 (from July 4th, mytype-sort-order value = 95), Post 5 (from July 5th, mytype-sort-order value = 90), Post 6 (from July 6th, mytype-sort-order value not set), Post 7 (from July 7th, expired="yes"). should be returned as follows : Post 4 (from July 4th, mytype-sort-order value = 95) Post 5 (from July 5th, mytype-sort-order value = 90) Post 6 (from July 6th, mytype-sort-order value not set) Post 3 (from July 3rd, mytype-sort-order value not set) Post 2 (from July 2nd, mytype-sort-order value not set) Post 1 (from July 1st, mytype-sort-order value not set) ( Post 7 not displayed because it's expired) I explained my current approach of trying to use meta-query here stackexchange-url ("here"), but I found anything new or made any progress myself, and with no responses to my first question I'm wondering if there's another way I could accomplish this. I've been able to not return expired posts, and order by "mytype-sort-order" meta_value_num OR order by date. The problem I keep running into is I can't order by BOTH "mytype-sort-order" meta_value_num AND date Even though I've done a lot with wordpress, my experience with creating custom queries is limited. I'm totally stuck and would REALLY appreciate some ideas. Thanks!
|
Though it might take some tweaking you can use the 'orderby' parameter on multiple values. The difficulty here is more in terms of logic, for example July 3 (date value) and the number 10 (meta value) do not really relate to one another, this would cause problems if not formatted correctly. You best bet is to convert the date to a format that will work with your meta values using the built in WordPress date format, a PHP date format ( most likely a unix timestamp, or timestamp) , or appending a fixed set of values to the date for ordering purposes. Multiple orderby example. This is not intuitive you have to look closely there are two values separated by a space, "title" AND "menu_order": <code> $query = new WP_Query( array( 'post_type' => 'page', 'orderby' => 'title menu_order', 'order' => 'ASC' ) ); </code> Date reference: http://www.php.net/manual/en/datetime.formats.php http://www.php.net/manual/en/function.strtotime.php http://codex.wordpress.org/Function_Reference/the_date Query: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
|
Custom query looking at multiple custom fields and properly sorting
|
wordpress
|
For a page template I am trying to include the 3 children of each page. That works fine. However as I want to include a different image for each of the children, I would like to add the <code> slug </code> of each child to the <code> li </code> on the parent page. I found something that places the <code> slug </code> of the parent page in the <code> li </code> 's: <code> <?php $slug = basename(get_permalink()); wp_list_pages('title_li=&sort_column=menu_order&link_before=<div class="'.$slug.'">&link_after=</div>&child_of='.$post->ID.''); ?> </code> Obviously not what I want, but at least nice to see that it is possible somehow to add something to the li in order to be able to identify it further with CSS. I would like the result to be something like: <code> <ul> <li class=child1-slug>...</li> <li class=child2-slug>...</li> <ul> </code> OR (as the example above shows) <code> <ul> <li><a><div class="child1-slug">...</div></a></li> <li><a><div class="child2-slug">...</div></a></li> </ul> </code> Can anyone push me in the right direction?
|
OK, I almost got it now... I extended the Walker_Page Class: <code> class Walker_Child_Classes extends Walker_page { function start_el(&$output, $page, $depth, $args, $current_page) { if ( $depth ) $indent = str_repeat("\t", $depth); else $indent = ''; extract($args, EXTR_SKIP); $output .= $indent . '<li class="' . apply_filters( 'the_title', $page->post_name, $page->ID ) . '"><a href="' . get_page_link($page->ID) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>'; } } </code> And added the following to my Page Template: <code> $sWalker = new Walker_Child_Classes(); wp_list_pages( array( 'title_li' => null, 'walker' => $sWalker, 'sort_column' => 'menu_order', 'child_of' => $post->ID ) ); </code> Which results in: <code> <ul class="timeline"> <li class="Future"> <li class="Current"> <li class="Past"> </ul> </code> I am not happy about the Capitals (it takes the Page name after all), but if this is what it is, then I can live with that... If anyone has a suggestion on how to get the real slug that would be highly appreciated! Edited the code with the suggestion of @mike23
|
add slug of child(ren) to li using wp_list_pages
|
wordpress
|
In my wordpress enviroment, I have a number of pages, and I also have a custom post type called casestudy. I have setup a page-clients.php that has some of it's own content on, I then use the <code> query_posts() </code> function to pull in all the posts with the post type casestudy. When viewing a single case study I wanting to show a nav, this nav needs to contain the links to pages, clients, and case study and underneath case studies I want to add all the posts that are of the custom post type 'casestudy' so far I have following, <code> <?php wp_list_pages(array('include' => '154, 136', 'title_li' => '', 'sort_column' => 'ID', 'sort_order' => 'DESC', 'depth' => '1')); ?> </code> How can I lists all the casestudy posts also, can it be done with <code> wp_list_pages() </code>
|
The <code> wp_list_pages() </code> function uses <code> get_pages() </code> , which accepts a <code> post_type </code> argument-array key, so you can use that same argument array key in `wp_list_pages(): <code> <?php wp_list_pages( array( 'post_type' => 'casestudy' ) ); ?> </code> Unfortunately, it looks like the <code> post_type </code> value must be a string , rather than an array (that is, if I'm reading the source correctly); which means that <code> wp_list_pages() </code> can only handle one post-type at a time. If you need to list all in one menu, you could try concatenating them: <code> <?php $pagelist = wp_list_pages( array( 'include' => '154, 136', 'title_li' => '', 'sort_column' => 'ID', 'sort_order' => 'DESC', 'depth' => '1' 'echo' => false ) ); $casestudylist = wp_list_pages( array( 'post_type' => 'casestudy', 'title_li' => '', 'echo' => false ) ); $concatenatedlist = $pageslist . $casestudylist; ?> <ul> <?php echo $concatenatedlist; </ul> </code> Codex references: <code> wp_list_pages() </code> <code> get_pages() </code>
|
wordpress wp_list_pages help
|
wordpress
|
I always assumed there was a way to exclude certain categories from being output in the loop using <code> get_the_category </code> , <code> the_category </code> , or one of the <code> term </code> related functions. After looking around it seems like the only way is to grab the array and just remove them by ID or name. For instance this is what I am using: <code> <?php // exclude category ID 12 as an example. foreach((get_the_category()) as $cat) { if (!($cat->cat_ID =='12')) echo '<a href="' . get_bloginfo('url') . '/category/' . $cat->category_nicename . '/">'. ' | ' . $cat->cat_name . '</a>'; } ?> </code> This looks kinda messy due to having a somewhat "hard-coded url" using <code> /category/ </code> ( I know I can also change this but it still seems counter intuitive). Is there no better way to exclude categories?
|
If the URL being "hard-coded" is the problem you can use <code> get_category_link </code> <code> foreach((get_the_category()) as $cat) { if ($cat->cat_ID !='12') echo '<a href="'.get_category_link($cat->cat_ID).'"> | ' . $cat->cat_name . '</a>'; } </code>
|
Better way to exclude category output for post/pages?
|
wordpress
|
I'm a bit of a PHP MySQL newb but i feel i need to bypass WordPress for the frontend of a site i'm building (it is mainly just RSS and JSON feeds). I was wondering if there are any tutorials or advice I should follow on this or just cut straight to it?
|
You want to include <code> wp-load.php </code> at the beginning of your script/page like this : <code> require_once("/path/to/wordpress/wp-load.php"); </code> You then have access to any WP functions. To manipulate the DB directly, have a look at <code> wpdb </code> .
|
WordPress as a backend only. How to output database content on public side without WordPress?
|
wordpress
|
I've been trying to decipher a way to display a message to a user on first login and can't seem to get it to work. I'm not sure what I'm missing, or if there's something else I need to do. Any help would be appreciated. I feel like I missing something here. <code> function ap_new_user_message() { $current_user = wp_get_current_user(); $user_ID = $current_user->ID; //global $user_ID; if( $user_ID ) { $user_info = get_userdata( $user_ID ); // If user_registered date/time is less than 48hrs from now // Message will show for 48hrs after registration if ( strtotime( $user_info->user_registered ) > ( time() - 172800 ) ) echo '<div>display a message</div>'; } } </code> Alternatively, If I could find a way of determining how many days it's been since a user was created I could do something similar. Perhaps by adding to the user meta table? <code> function first_login($login) { global $user_ID; $user = get_userdatabylogin($login); update_usermeta( $user->ID, 'first_login', date(), time() ); } add_action('wp_login','first_login'); </code> And then calling for it <code> if first_login(date, time) == (today, ago) { #do something } </code> Update: Milo's code worked great. However, I needed it to work with Eric Meyer's Simple Modal Login. I found this function within simplemodal-login.php and peter's login redirect. <code> function login_redirect($redirect_to, $req_redirect_to, $user) { if (!isset($user->user_login) || !$this->is_ajax()) { return $redirect_to; } if ($this->is_plugin_active('peters-login-redirect/wplogin_redirect.php') && function_exists('redirect_to_front_page')) { $redirect_to = redirect_to_front_page($redirect_to, $req_redirect_to, $user); } echo "<div id='simplemodal-login-redirect'>$redirect_to</div>"; exit(); } </code> and added Milo's redirect to it like so: <code> function login_redirect($redirect_to, $req_redirect_to, $user) { $regtime = strtotime($user->user_registered); $now = strtotime("now"); $diff = $now - $regtime; $hours = $diff / 60 / 60; if (!isset($user->user_login) || !$this->is_ajax()) { return $redirect_to; } if ($this->is_plugin_active('peters-login-redirect/wplogin_redirect.php')&& function_exists('redirect_to_front_page')) { $redirect_to = redirect_to_front_page($redirect_to, $req_redirect_to, $user); } if( $hours < 48 ){ $redirect_to = "/somepage/"; // it's been less than 48 hours, redirect to message. } echo "<div id='simplemodal-login-redirect'>$redirect_to</div>"; exit(); } </code> Now I just need to determine how to force a model popup when a users reaches a certain page.
|
here's an example that hooks login_redirect and checks when their account was created, then redirects them to a url of your choice if it's been less than 48 hours: <code> function my_redirect( $to, $requested, $user ){ if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied return $to; } $regtime = strtotime($user->user_registered); $now = strtotime("now"); $diff = $now - $regtime; $hours = $diff / 60 / 60; if( $hours < 48 ){ return "/somepage/"; // it's been less than 48 hours, redirect to message. } else { return admin_url(); } } add_filter('login_redirect', 'my_redirect', 10, 3); </code>
|
Redirecting or displaying a message on first login
|
wordpress
|
I just definsed at Setting> Reading a page I have created called "home" as my homepage. The change was ok, but since them all my internal pages url shows an extra /home/in their urls. How can I avoid it? Examples: Before: www.mydomain/internalpage/ After the change: www.mydomain* /home/ *internalpage/
|
What @iampearce said is basically right, but to be a bit more specific: look in Settings > Pewrmalinks. Choose one of the defaults - maybe %year%/%postname% - and click Save. Does that help? If that doesn't fix it, look in Settings > Reading and check that the "front page" and the "posts page" are not set to the same page via the dropdowns there. If you want your front page (home page) to be the blog page, just choose "Your Latest Posts". Best of luck!
|
How to exclude my home page from url of my internal pages?
|
wordpress
|
Is there a query I can run on my wordpress database so that I can change all instances of <code> www.mydomain.com </code> to <code> localhost/mylocalsite.com? </code>
|
Try this plugin: http://wordpress.org/extend/plugins/search-and-replace/ - It helped me dozens of times. Or try this query: <code> UPDATE tablename SET tablefield = replace(tablefield, "findstring", "replacestring"); </code> Or try this method, dump the database, open the SQL file, do a find and replace in a text editor then reimport it. Take care to backup your database prior to making any operations and changes!
|
Rewrite database urls
|
wordpress
|
I have my WordPress blog up and running on an IIS7 server and I installed W3 Total Cache. At some point prior to WordPress 3.2 upgrade, everything seemed to be working, but since then (and quite possibly, some plugin installations) all it does is add a single <code> <meta> </code> tag after the <code> <head> </code> tag and its footer saying "Performance Optimization by...". It doesn't cache anything, it doesn't change browser cache settings in the response header. It doesn't work. I can't work out what is going on, so I'm hoping someone here recognises this issue and can help. I have WordPress 3.2.1 and W3 Total Cache 0.9.2.3. The other active plug-ins I have are: Akismet 2.5.3 FeedBurner FeedSmith Extend 1.0.0 Google Analytics for WordPress 1.1.3 Recommended Reading: Google Reader Shared 4.0.4 Share and Follow 1.54.1 SyntaxHighlighter Evolved 3.1.3 TinyMCE Valid Elements 0.3 Tweet Blender 3.3.14 Twitter Facebook Social Share 2.0.0 I have turned on the debugging feature but nothing gets appended to the page. I will continue to investigate but if anyone can see where my issue lies, please answer accordingly. Why won't W3 Total Cache, cache?
|
After more investigation last night, I discovered the problem lay in a malformed PHP file within my very simple child theme. The child theme was just a stylesheet and a PHP file, so it wasn't difficult to determine where the problem lay within the theme. A quick look at the PHP showed that it included just <code> <?php?> </code> . I deleted the file and now everything is working again.
|
W3 Total Cache and IIS7 not doing much
|
wordpress
|
I am making a plugin that needs a page that can be accessed from the outside, pretty much like an API, and have the url like so, http://xxxxx/custom_method?parameter=xxxxx&something=xxxx is there a clean way to do this? Thanks in advance.
|
The WordPress Way of doing it is using <code> query_vars </code> so first you add you vars to the array: <code> //add to query vars function add_query_vars($vars) { $new_vars = array('custom_method','cm_parameter'); $vars = $new_vars + $vars; return $vars; } add_filter('query_vars', 'add_query_vars'); </code> then you can check in your plugin for the vars: <code> global $wp; if (array_key_exists('custom_method', $wp->query_vars) && isset($wp->query_vars['custom_method'])){ //do your stuff } </code>
|
Custom routing for plugins
|
wordpress
|
I've customized a theme and am having some problems with search results using multiple-word queries. Site is live at www.abetterworldbydesign.com Searching for a single word works as expected. Searching for multiple words that should have returned results shows blank results. Oddly enough, manually changing the "+" character in the URL to "&" displays the results correctly but only shows the first word in the header "Search results for:_". My code in search.php for initializing WP_Query follows exactly the code listed in the codex . Full code for search.php on pastebin . Code for searchform.php below. <code> <form id="searchform" name="searchform" method="get" action="<?php echo home_url(); ?>"> <div> <input type="text" id="s" name="s" /> <input type="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'richwp' ); ?>" /> </div> </form> </code>
|
Answer from Richard M on the stackexchange-url ("question originally asked on StackOverflow"): Replacing line 21 on search.php with <code> $search_query[$query_split[0]] = urldecode($query_split[1]) </code> resolved it.
|
Search Results not displaying for multiple word search
|
wordpress
|
I have added query_posts() to my index.php file to modify the loop on the posts page: <code> query_posts( 'cat=-4,-7' ); get_template_part( 'loop', 'index' ); </code> This works correctly, but when I click on "Older Posts" (link to /page/2), the latest posts show up instead of the previous ones. How can I get my pagination to show the correct posts?
|
different approach: <code> global $wp_query; $args = array_merge( $wp_query->query, array( 'category__not_in' => array(4,7) ) ); query_posts( $args ); get_template_part( 'loop', 'index' ); </code> if this approach should not work, please check if one or more of the plugins is interfering - deactivate all plugins; if the exclusion of categories works then, re-activate one plugin at a time to find the interfering plugin.
|
Pagination Not Working When Modifying Loop Based on Post Category
|
wordpress
|
I notice that in some plugins you can override functions by ... Creating an uploads folder Creating a folder with the plugin name Using the following code <code> if (!function_exists('function_name')) { function function_name() { } } </code> Is this standard for all Wordpress plugins or only if they're written in a specific way?
|
If the plugin displays content via any function, the code: <code> if(!function_exists('function_name')) function_name(); </code> ... is used for safety. If your plugin is disabled, and the <code> if (!function_exists('function_name')) </code> is missing, your theme will throw a fatal error.
|
Overriding functions in wordpress plugins
|
wordpress
|
Just wondering, If any body have integrated Chase Paymentech Payment Gateway with WordPress for Shopping Cart purpose?
|
The best source for information on this is the getshopped.org/forums/ forums. It appears that there are a couple of posts regarding this gateway in the forums, but the forums appear down at the moment. Also, getshopped.org maintains a directory of developers that can help you develop a new payment gateway. These gateways are relatively simple to build (I'm working on one right now) depending on the complexity of the merchant API. There's no reason that the gateway cannot be build; it's just a matter of finding someone to do it. And, I do not believe that the gateway you are looking for currently exists.
|
Wordpress Ecommerce Chase Paymentech Integration
|
wordpress
|
I'm looking for a plugin that pulls an Image from a Wordpress Posts Gallery (Note NOT the Featured Thumbnail, we have thousands of posts and can't retroactively go back and set a Featured image for each post..) Also some of the plugins I've tested don't let you specify exact dimensions, the Wordpress Get The Image Plugin let's you pull an image from the gallery like I want then you set the width but it tries to maintain proprotions. So basically I need it to do exactly that except not try and maintain proportions but rather do a Zoom Crop if that makes sense.
|
No need for plugins. Some simple code in your theme can do this job. You can get any size image by passing an array of width and height for the size parameters, but to get a cropped image, you have to predefine it as an premade image size so that the crop gets created properly at upload time. To do that, in your theme's functions.php file, you need to add something like this: <code> function themename_setup() { add_image_size( 'themename-some-description-of-the-size', 100, 100, true ); } add_action( 'after_setup_theme', 'themename_setup' ); </code> That's the width and height you want, and the "true" saying you want it to crop to the center of the image. Now you need code in the Loop to pull either the Featured Image (if there is one) or the First Image from the gallery (if there's no featured image). This code would go into The Loop, so that you're getting it for the current post. <code> if ( has_post_thumbnail() ) { $thumb_id = get_post_thumbnail_id(); } else { $attachments = get_children( array( 'post_parent' => get_the_ID(), 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'numberposts' => 1) ); $attachment = array_shift($attachments); $thumb_id = $attachment->ID; } </code> Finally, you need to display the resulting image: <code> echo wp_get_attachment_image($thumb_id, 'themename-some-description-of-the-size'); </code> Simple. However, there's one caveat: Your already uploaded images won't have this size image created for them. So WordPress will pick the best fitting image and try to use that. This is not always ideal. Use a plugin like Regenerate Thumbnails after you create the code, and it will go through all your images and have WP regenerate the thumbnails, creating the proper image sizes for all of them. Also remember when making your theme that this code is more of a guideline than code you should actually use. I wrote it to teach you how to do it yourself and to customize your theme, not to be copy-pasta. You can find out more about image handling in themes here: http://ottopress.com/2011/photo-gallery-primer/
|
Getting top Image From the Gallery and printing out a thumbnail with Exact Dimensions
|
wordpress
|
I have imported some tables from my online wordpress database to my local to work on. However now I am getting some weird sql errors that I don't get online. I can see that the code of the plugin I am working on has some references (aliases?) that don't appear to reference anything that I see when I do a search: <code> $result = $wpdb->get_row( 'SELECT re.* FROM ' . EVENT_ESPRESSO_RECURRENCE_TABLE . ' re INNER JOIN ' . EVENTS_DETAIL_TABLE . ' ed ON re.recurrence_id = ed.recurrence_id WHERE re.recurrence_id = ' . $recurrence_id . ' ORDER BY ed.start_date ASC LIMIT 1', ARRAY_A ); </code> What is table 're'? In re.recurrence_id?
|
're' is the alias you give to EVENT_ESPRESSO_RECURRENCE_TABLE. The error you're seeing is probably because the EVENT_ESPRESSO_RECURRENCE_TABLE constant isn't defined. Do a <code> var_dump( $wpdb->last_query ) </code> just below that code to see the final SQL statement.
|
Wordpress tables and aliases?
|
wordpress
|
Here's my code: <code> function widget($args, $options) { extract($args); global $post; $post_type = $options['post_type']; $num_of_posts = $options['limit']; // Create a new instance $second_query = new WP_Query( array( 'post_type' => "$post_type", 'posts_per_page' => "$num_of_posts", 'post_status' => 'publish', ) ); // The Loop if ($second_query->have_posts()) : while( $second_query->have_posts() ) : $second_query->the_post(); $content .= '<span><a href="' .get_permalink(). '">' . get_the_title($post->ID) . '</a></span>'; $content .= '<div>' .get_the_post_thumbnail($post->ID, array(290,290)). '</div>'; $content .= '<p>' . get_the_excerpt() . '</p>'; endwhile; else : $content = '<p>No ' . $options['post_type'] . 's found.</p>'; endif; wp_reset_postdata(); $title = "<h3>" . $options['title'] . "</h3>"; echo $before_widget.$title.$content.$after_widget; } </code> Everything displays fine except the thumbnail :-\
|
Try just get_the_post_thumbnail(). Leave the $post-> ID out of it. Edit: Never mind, get_the_post_thumbnail does require the ID. I'd use the get_the_ID() function instead of $post-> ID, but that shouldn't matter.
|
get_the_post_thumbnail() returns nothing?
|
wordpress
|
Encountered an infuriating issue where I f i want to add multiple linebreaks for layout between paragraphs, Wordpress doesn't recognize them in th wysiwig editor. If I enter them in the code window, and publish they DO save, but the next time the Wysiwig is edited and published those breaks disappear. is there a workaround or a plugin hat lets Tinymce handle this better?
|
I use TinyMce Advanced. In the TinyMce Advanced settings it gives you to the choice to stop removing the line-breaks. You might give it a try. This is the first plug-in I install after adding a WP Website. Link: http://wordpress.org/extend/plugins/tinymce-advanced/
|
Wordpress Tiny MCE won't accept line breaks
|
wordpress
|
This question is similar to stackexchange-url ("Multisite with entirely different domains?") which was not answered. I am re-asking. I want to host multiple domains using WP multisite, which is installed and working normally in "multiple subdomains" mode. This creates multiple WP sites like <code> site1.domain.com site2.domain.com </code> I want to use <code> www.domain1.com www.domain2.com </code> I've tried the Wordpress MU domain mapping plugin but I'm not satisfied with its behavior. This plugin seems to simply redirect the user, ie. the user enters <code> www.domain1.com </code> and the browser is sent to <code> site1.domain.com </code> I don't want the user to know they aren't on domain1.com. I also tried setting up VirtualHosts in Apache: <code> <VirtualHost *:80> ServerName site1.domain.com ServerAlias domain1.com ServerAlias www.domain1.com </VirtualHost> </code> But this also seems to produce a redirect to <code> site1.domain.com </code> in the users's browser.
|
Domain mapping is the correct answer to your question, because that isn't how the domain mapping plugin works at all. Take a look at http://ottopress.com . It really lives at http://ottodestruct.com/op/ , but you wouldn't know it, would you? It's a domain mapped site on a multisite installation. If you're getting a redirect to the wrong URL, check to be sure that you set up the new domain as the "primary" in the domain mapping. The primary one is the one that the others will redirect to.
|
Multisite with Different Domains
|
wordpress
|
How can I allow people to post comments on a page? I've put this into my page template: <code> <?php comments_template(); ?> </code> but it just says at the bottom of my page "Comments closed". UPDATE: If I can allow comments for one specific template for a page that would be great.
|
Have you checked under Admin -> Settings -> Discussion and for individual pages, under pages and quick-edit or the discussion area in edit page below the page editor? When the last one does not show, click screen options near the top right, and tick discussion there, then scroll back down.
|
How can I add comments to a page?
|
wordpress
|
I am looking into having the two following roles: Editor Publisher and the following different states a post can be in: Draft Ready for publication Published The workflow I am seeking is: An editor writes a blogpost. It is a draft . Once it is final, the editor marks ist as ready for publication . From that moment on, the editor looses the ability to edit the blogpost . The publisher reviews, edits and publishes the blogpost . Is this possible with Wordpress? If not, is there a state of the art plugin for such a workflow? It seems like an obvious workflow.
|
Allow me to translate the roles and states into WP parlance: Roles: Editor -> Author Publisher -> Editor States: Draft -> Draft Ready for publication -> Pending Review Published -> Published The only thing you need a plugin for is this bit: "From that moment on, the author looses the ability to edit the blogpost."
|
Publication Workflow
|
wordpress
|
I'm trying to empty an option created with the Settings API and failing. <code> update_option ( 'my_option', '' ); </code> appears to do nothing, whereas <code> delete_option ( 'my_option' ); </code> destroys the whole option causing other problems. I just want to empty the values and reset it. I'm really clueless how to implement this correctly. Can anyone help? 50 point bounty up for grabs! <code> <?php //Create the menus add_action( 'admin_menu', 'tccl_menu' ); function tccl_menu() { //add_menu_page: $page_title; $menu_title, $capability, $menu_slug, $function, $icon_url, $position add_menu_page( 'Control', 'Control', 'manage_options', 'tccl-main', 'tccl_menu_page_main', plugins_url( '/traffic-control/images/wp-icon.png' ), '2.2' ); //add_submenu_page: $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function add_submenu_page( 'tccl-main', 'Domains', 'Domains', 'manage_options', 'tccl-domains', 'tccl_menu_page_domains' ); } //Menu callback functions for drawing pages function tccl_menu_page_main() { ?> <div class="wrap"> <h2>Control</h2> <form action="options.php" method="post"> <?php settings_fields( 'tccl_settings_main' ); ?> <?php do_settings_sections( 'tccl_settings_main' ); ?> <input name="Submit" type="submit" value="Save Changes" class="button-primary" /> </form></div> <?php } function tccl_menu_page_domains() { $tccl_domains = get_option( 'tccl_settings_domains' ); if ( $_POST['trigger'] ) { $p_delete_all = $_POST['delete_all']; $p_ids = $_POST['ids']; #Get IDs $p_deletes = $_POST['deletes']; #Get deletes if ( $p_delete_all ) { //unset( $tccl_domains ); //delete_option( 'tccl_settings_domains' ); foreach( $tccl_domains as $option ) { $option = false; } $tccl_domains = array (); update_option( 'tccl_settings_domains', $tccl_domains ); } elseif ( is_array( $p_ids) ){ foreach ( $p_ids as $id ) { if ( $p_deletes[$id] ) { //unset( $tccl_domains[$id] ); } } } } ?> <div class="wrap"> <?php screen_icon( 'themes' ); ?> <h2>Control</h2> <form action="options.php" method="post"> <?php settings_fields( 'tccl_settings_domains' ); ?> <?php do_settings_sections( 'tccl_settings_domains' ); ?> <input name="Add" type="submit" value="Add Domains" class="button-primary" /> </form> <form action="" method="post"> <input type="hidden" name="trigger" value="1"> <h3>Live Domains</h3> <table class="widefat"> <thead> <tr> <th><input type="checkbox" name="delete_all" value="1"></th> <th>Domain Name</th> </tr> </thead> <tfoot> <tr> <th><input type="checkbox" name="delete_all" value="1"></th> <th>Domain Name</th> </tr> </tfoot> <tbody> <?php print_r ( $tccl_domains ); if ( is_array( $tccl_domains ) ) { foreach ( $tccl_domains as &$value ) { echo '<tr><td><input class="large-text" type="checkbox"></td><td>'.$value['text_area'].'</td></tr>'; } } else { echo '<tr><td colspan="2">No domains entered. Use the form above to add domains to this list.</td></tr>'; } ?> </tbody> </table> <br /> <input name="Delete" type="submit" value="Delete Domains" class="button-secondary" /> </form> <script> jQuery('input[name=delete_all]').click(function () { if (jQuery(this).is(':checked')) { jQuery('tbody input[type=checkbox]').each(function () { jQuery(this).attr('checked', true); }); jQuery('input[name=delete_all]').attr('checked', true); } else { jQuery('tbody input[type=checkbox]').each(function () { jQuery(this).attr('checked', false); }); jQuery('input[name=delete_all]').attr('checked', false); } }); </script> </div> <?php } //Settings add_action( 'admin_init', 'tccl_admin_init' ); function tccl_admin_init() { // register_setting: $option_group, $option_name, $sanitize_callback register_setting( 'tccl_settings_main', 'tccl_settings_main', 'tccl_settings_main_validate' ); register_setting( 'tccl_settings_domains', 'tccl_settings_domains', 'tccl_settings_domains_validate' ); // add_settings_section: $id, $title, $callbak, $page add_settings_section( 'tccl_sections_main', 'Main Settings', 'tccl_sections_main_text', 'tccl_settings_main' ); add_settings_section( 'tccl_sections_domains', 'Add Domains', 'tccl_sections_main_text', 'tccl_settings_domains' ); // add_settings_field: $id, $title, $callback, $page, $section, $args add_settings_field( 'tccl_fields_main_input', 'Enter text here...', 'tccl_fields_main_input', 'tccl_settings_main', 'tccl_sections_main' ); add_settings_field( 'tccl_fields_domains_input', 'Add domains to the list below. Multiple domains should be seperated by commas.', 'tccl_fields_domains_input', 'tccl_settings_domains', 'tccl_sections_domains' ); } //Sections callback functions function tccl_sections_main_text() { echo '<p>Enter your settings for the main options in the main section...</p>'; } //Field callback functions function tccl_fields_main_input() { //Get option 'text_string' value from the database $options = get_option( 'tccl_settings_main' ); $text_string = $options['text_string']; //Echo the field echo "<input id='text_string' name='tccl_settings_main[text_string]' type='text' value='$text_string' />"; } function tccl_fields_domains_input() { //Get option 'text_string' value from the database $options = get_option( 'tccl_settings_domains' ); $text_area = $options['text_area']; //Echo the field echo "<textarea id='text_area' name='tccl_settings_domains[text_area]'>$text_area</textarea>"; } //Settings callback functions (validation) function tccl_settings_main_validate( $input ) { $valid['text_string'] = preg_replace( '/[^a-zA-Z]/', '', $input['text_string'] ); if ( $valid['text_string'] != $input['text_string'] ) { //add_setting_error: $title, $id, $error_message, $class add_settings_error( 'tccl_fields_main_input', 'tccl_texterror', 'Incorrect value entered!', 'error' ); } return $valid; } function tccl_settings_domains_validate( $input ) { $options = get_option( 'tccl_settings_domains' ); $options[] = $input; return $options; } ?> </code>
|
If you wrote your code correctly, then delete_option would be the correct way. The question isn't how to clear the option; the question is how to structure your code such that the "option does not exist" case is a valid case. Think about it. The first time you start this code, that option isn't going to exist at all, right? Your code should be perfectly capable of handling that case, since it's the first thing the user is ever going to see. get_option() accepts a default value if the option does not exist. So use that. If you had an empty array for the default, for example, you'd have code like this: <code> $options = get_option('whatever',array()); </code> Assuming you're using the settings API, then you should use the <code> isset </code> function in if statements to account for the missing-field case. Something like this: <code> if (!isset($options['name'])) { //... the option isn't set to something } else { //... the option is set to something } </code> And handle each case of actual use of the option accordingly.
|
What's the best method for emptying an option created with the Settings API?
|
wordpress
|
I would like to hook the keydown event in the TinyMCE Editor on the edit post admin page. I managed to hook the HTML content editor using the following code: <code> jQuery('#content').keydown(function(){ alert("keydown") }); </code> Here is my failed attempt at hooking the TinyMCE editor. The problem is that the editor hasn't been init yet so the variable ed is undefined. <code> var ed = tinyMCE.getInstanceById('tinymce'); ed.onChange.add(function(ed, l) { alert("keydown"); }); </code> Any help would be much appreciated!
|
the TinyMCE Editor has its own keydown event handler and its hooked to a function on initiation so to do that you can create a tinymce plugin or use the wordpress initiation of it with <code> tiny_mce_before_init </code> hook like this: <code> add_filter( 'tiny_mce_before_init', 'wpse24113_tiny_mce_before_init' ); function wpse24113_tiny_mce_before_init( $initArray ) { $initArray['setup'] = <<<JS [function(ed) { ed.onKeyDown.add(function(ed, e) { //your function goes here console.debug('Key down event: ' + e.keyCode); }); }][0] JS; return $initArray; } </code>
|
Hook the Keydown Event in the TinyMCE Post Editor
|
wordpress
|
We have a pretty basic load balancing setup with 3 web servers behind a load balancer connected to the same db server and pointing their wp-content/uploads folder to an nfs share. We have the first server rsynching the wordpress files across the other 2 in a cron job to keep the servers in sync (all wp-admin stuff is done on the first server) I'm wondering what the best way is to upgrade the entire cluster at once with minimal downtime. If I update wordpress on the first server, will the db versioning cause the other 2 servers to stop working? Or can I just update the first server then rsync the files across without any downtime?
|
I don't think the database schema ever changes so drastically that the versions of wordpress on box 2 + 3 would be prevented from reading from the DB after you've updated on box 1, however it depends what version you are upgrading from. Why not set a similar environment locally and test upgrading site 1, while still trying to visit site 2.
|
Updating servers at once in web cluster
|
wordpress
|
I want to add a field to the comments and have used these codes. functions.php <code> function my_fields($fields) { $fields['url2'] = '<p class="comment-form-url2"> <label for="url2">URL hittad på webben</label> <input id="url2" name="url2" type="text" value="" size="30" /> </p>'; return $fields; } add_filter('comment_form_default_fields','my_fields'); </code> comments.php <code> comment_form(); </code> Questions It does not add an extra field in admin comment. Should it, or not? It does not seem to save the extra field. I tried to var dump the comment array. Why not?
|
There are a couple other hooks in the comment form that you can use. Where you're hooking on only displays if the user isn't logged in. If you want that field for all users (logged in or not), you need to add your form by hooking into both <code> comment_form_after_fields </code> and <code> comment_form_logged_in_after </code> , both of which are actions, and echo out the new field. <code> <?php add_action( 'comment_form_logged_in_after', 'pmg_comment_tut_fields' ); add_action( 'comment_form_after_fields', 'pmg_comment_tut_fields' ); function pmg_comment_tut_fields() { ?> <p class="comment-form-title"> <label for="pmg_comment_title"><?php _e( 'Title' ); ?></label> <input type="text" name="pmg_comment_title" id="pmg_comment_title" /> </p> <?php } </code> Check out this tutorial I wrote (the example above is from it). Covers everything from adding fields to saving the data to adding a meta box so you can edit the extra fields on the back end too.
|
Using filter to add additional fields to comment_form()
|
wordpress
|
An image speaks for a thousand words so please bear with me: http://interativo.modateca-sc.com/ The last post appears twice. Once as the feature post and then again on the "main blog part" where the ten or so latest posts appear. Is there a way to make it not appear again? Thanks :)
|
Go to the code of "Main blog part", loop.php i guess... or any code your theme uses.. Find get_posts and use exclude parameter to exclude the post from there. Pass id of featured post as exclude... Here is reference... http://codex.wordpress.org/Template_Tags/get_posts
|
How *not* to show the last post on the latest posts list
|
wordpress
|
I am using a custom login form imported on my theme's home page through jqModal. In that, when i successfully login it redirects to the same page. I want to redirect based on the logged in user role. I will prefer a response with some editing in my functions.php or adding a mini plugin. Because I dont want wordpress original files to be edited for future updating hassles.
|
I used Theme My Login Plugin and modified its templates as per my requirements. I think its the best plugin as per my requirements were concerned. You may check yours. Also if you want to see the working inside the code, this plugin coding approach is nice and adaptive.
|
wordpress custom login successful redirect hook
|
wordpress
|
I am in very big need of a user management system just like the one that wordpress uses but without being blog related. I need to be able to manage users and apply certain privileges depending on user level. I tried to take apart the WP engine and take out the users part but I think it's so tied to the whole engine, I wasn't able to... Does anyone know of any scripts that offer the same register, login etc functions? Also, could it be open source? I already bought my first user management system but it sucks really bad... :( Thanks in advance to anyone willing to help me. Andy
|
you can still use WordPress and disable the front end functionality, or like @OneTrickPony suggested you can try BackPress which is a PHP library of core functionality for web applications that grew out of WordPress.
|
User management system similar to wordpress one?
|
wordpress
|
I have custom post type 'Product', and 2 custom taxonomies 'category' and 'product status'. What i am trying to do is list categories in page template and show how many total products in category and how many of them have status 'available' Some thing like this Category | No. of products | Products available Can any one show how to get posts that are in particular category and have particular status value from other taxonomy...
|
I'm sure that a custom sql query would work much better but here is an option using the WordPress Tools available <code> //first get all categories $categories = get_terms( 'category', array( 'orderby' => 'count', )); //then create an array for easier processing foreach ( $categories as $cat ) { $slugs[] = $cat->slug; $counts[$cat->slug]['count'] = $cat->count; } //then loop over the categories and for each one create a "query" to count the number of available products foreach($slugs as $term){ $products = get_posts(array( 'post_type' => 'product', 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( $term) ), array( 'taxonomy' => 'product_status', 'field' => 'slug', 'terms' => array( "available"), 'operator' => 'NOT IN', ) ) )); $counts[$term]['available'] = count($products); } //then all the is left is to print everyting Out if (count($counts) > 0){ echo '<table><tr><td>Category</td><td>No. of products</td><td>Products available</td></tr>'; foreach ($counts as $key => $val){ echo '<tr><td>'.$key.'</td><td>'.$var['count'].'</td><td>'.$var['available'].'</td></tr>'; } echo '</table>'; } </code>
|
query multiple taxonomy and show post count
|
wordpress
|
I have to run a PHP script through real cron (WP cron being too unreliable). Within that script, I need $wpdb to insert data into WordPress table. But of course $wpdb will not be available as WordPress would not be initialized. Right? So, my question is how to 'include' WordPress/initialize WordPress environment to do such tasks? How about require_once("wp-load.php")?
|
You can use real cron to trigger WP cron - by fetching <code> wp-cron.php </code> file from root ( snippet from quick google search ). That will take care of environment and everything.
|
Initialize WordPress environment to use in a real cron script
|
wordpress
|
I would like a second <code> WP_Query </code> on a custom post type's single page to return 5 posts, starting with two before the current post, so that I get this: The-one-before-the-previous post Previous post Current post Next post The-one-after-the-next post How can I do this? <code> offset </code> is only good if I know the number of the current post. In pseudo-code it's easy: <code> $gallery = new WP_Query(array( 'post_type' => 'artwork', 'posts_per_page' => 5, 'fake-offset' => $current->ID-2 //This is imaginary )); </code> Thanks in advance!
|
Instead of using the <code> offset </code> parameter, take a look at the <code> post_where </code> filter examples under the Time Parameters section of WP_Query codex page . You could just add a filter that returns posts that are less than the current post's date.
|
How to make a second query offset -2 from current post
|
wordpress
|
I am trying to get paging to work on my future post loop, but to no avail. I am getting no links, when I expect them at the bottom, for pagination despite there being several valid posts in the database. <code> <?php $args = array( 'post_type' => 'program', 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'posts_per_page' => 1, 'post_status' => "future", 'order_by' => 'date', 'order' => 'ASC' ); $program = new WP_Query; $program->query( $args ); if($program->have_posts()): while($program->have_posts()): $program->the_post(); ?> //The content loop <?php endwhile; ?> <div><?php previous_posts_link('&laquo; Previous'); ?></div> <div><?php next_posts_link('More &raquo;'); ?></div> <?php endif; ?> <?php wp_reset_query(); ?> </code> Update Further Info I have established that $program-> max_num_pages always displays the correct number of pages, so using the <code> offset </code> argument for <code> WP_Query </code> , I have been able to roll my own paging. But this seems like it's asking for trouble!! Update Further Info I have taken the rather drastic step of extending the WP_Query object. This is really over the top, but I have to make this work: <code> class MF_Query extends WP_Query{ function __construct(array $args){ if(!array_key_exists('posts_per_page',$args)) $args['posts_per_page'] = 10; $args['offset'] = (isset($_GET['page'])?($_GET['page']-1)*$args['posts_per_page']:0); parent::query($args); } function mf_next_page($link_text = "Next"){ $curPage = intval((isset($_GET['page'])?$_GET['page']:1));//Use 1 if $_GET['page'] not set $link = "<a href='".remove_post_vars(curPageURL()); if($curPage<$this->max_num_pages){ return $link.constructQuery($this->merge(array("page"=>$curPage+1),$_GET))."'>".$link_text."</a>"; } else { return false; } } function mf_prev_page($link_text = "Prev"){ $curPage = (isset($_GET['page'])?$_GET['page']:1);//Use 1 if $_GET['page'] not set $link = "<a href='".remove_post_vars(curPageURL()); if($curPage>1){ return $link.$this->constructQuery($this->merge(array("page"=>$curPage-1),$_GET))."'>$link_text</a>"; } else { return false; } } private function constructQuery(array $query){ $url_ext = "?"; foreach($query as $k => $v){ $url_ext .=$k."=".$v."&amp;"; } $url_ext = substr($url_ext, 0, -5);//chop last ampersand off return $url_ext; } private function merge($get, $put){ //Get values from one array, and put them in another (overriding existing values if appropriate) foreach ($get as $k => $v){ $put[$k]=$v; } return $put; } } </code>
|
Adjacent post fetching relies on quite a bit of custom SQL inside. One of the assumptions it makes in that SQL is that you are only looking for published post. You can use filter in <code> get_adjacent_post() </code> (that is used internally by those next/previous functions) to alter the query and get rid of published only limitation.
|
Paging on a future post loop?
|
wordpress
|
I'm working on a custom theme that I've inherited to maintain. At the top of the homepage there is a header area with some images generated by <code> get_the_post_thumbnail </code> . The call to <code> get_the_post_thumbnail </code> outputs img objects that are set to a specific width/height by their html attributes. Here's the code and output: Inside a loop <code> <?php echo get_the_post_thumbnail( $id, array( 300, 300 ) ); ?> </code> Html output <code> <img width="215" height="93" src="[img filepath]" class="attachment-300x300 wp-post-image" alt="[img name]" title="[img name]"> </code> I need to reset the attribute height and width dimensions to something other than 215 x 93 . I can't find anywhere this is being set (checked in wp-admin as well as functions.php as well as anywhere else where I thought it might be). I am also not finding any places where <code> set_post_thumbnail_size </code> is being called with these values. Can anyone tell me where to reset these values? Thanks.
|
You can look at adding an image size to your themes <code> functions.php </code> file. http://codex.wordpress.org/Function_Reference/add_image_size You then just need to do <code> <?php the_post_thumbnail('image-size-name'); ?> </code> and it will pull out the image based on the sizes you set.
|
img width and height attributes being set by get_the_post_thumbnail
|
wordpress
|
my question is... I have 2 pages & 2 subpages in each page. like: page1 --> subpage1 --> subpage2 page2 --> subpage1 --> subpage2 & my Menu is Page1 page2 Now if i select subpage1(from page1) means the page1 need to active and highlight the menu. if i select subpage1(from page2) means it need to highlight page2 and page2 menu in active. how to do this? please help me to get rid of this problem.i need to implement in my wordpress website.
|
To highlight page 1 and page 2 use <code> current-menu-parent </code> class
|
Active Menu Highlighter with Subpages?
|
wordpress
|
I'm trying to add/ update additional values to an option created with the Settings API. I'm trying to do this with my validation callback function, but I'm not getting very far. Here is my code: <code> function tccl_settings_option_validate( $input ) { add_option( 'tccl_settings_option', $input ); } </code> This is causing a pretty big error. How should I be doing this? What I would like to do is use the validation callback to add values to the option array without overwriting it.
|
Get the option, modify only the values you need to modify in it, then return the results. <code> function tccl_settings_option_validate( $input ) { $options = get_option('tccl_settings_option'); // modify $options using data from $input as needed return $options; } </code>
|
Using the Settings API, how should I add multiple values to an option?
|
wordpress
|
Can anyone recommend plugin that I can use to add a table to a page? I've seen ones that use static data-- you hardcode the figures in the table. I want to pull the data from a custom db table and put it in a table. I looked at WP Table Reloaded , but I'm not sure whether, it's possible to use it with dynamic data. Any suggestions? Thank you.
|
Set up a custom page template and in the content of the template use WPDB to query your table. Example to get a row: <code> $mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10"); </code>
|
Recommendation for a Dynamic Table Plugin
|
wordpress
|
I would like to exclude a category from my categories sidebar widget. If I understand the way this works, the sidebar.php code is not in use since the widget is displaying the categories. (something similar was discussed in this support topic: http://wordpress.org/support/topic/problem-trying-to-hide-a-category-in-the-sidebar ). How can I modify the query used by the widget; or is there another means of excluding specific categories from inclusion in the category list?
|
I'll answer my own question so that the results are in the discussion thread. All of the suggestions I've seen don't seem to work with the current version of WordPress (3.2). There are some widgets which will execute PHP script directly, used in conjunction with the correct query, this qualifies as a solution. Plugins with PHP capability: PHP Code Widget http://wordpress.org/extend/plugins/php-code-widget/ Exec-PHP http://wordpress.org/extend/plugins/exec-php/ I used PHP Code Widget myself. The query: <code> <?php wp_list_categories('show_count=1&exclude=12,24&title_li='); ?> </code> (or similar). You still need to lookup the value of the category or categories to exclude; in this case, I excluded categories 12 and 24
|
Customize category query in widget
|
wordpress
|
I used stackexchange-url ("Mixing custom post type and taxonomy rewrite structures?") and http://wordpress.org/support/topic/set-category-to-a-custom-post-type-automatically?replies=10 to create my custom post type. But I am getting some headers already sent errors on my site. Specifically when I go to save a page or try to log in. Can somebody check the code to make sure it is correct. <code> // PROJECTS add_action('init', 'create_work_projects'); function create_work_projects() { register_taxonomy( 'project_category', array(), array( 'hierarchical' => true, 'labels' => array( 'name' => 'Categories', 'singular_name' => 'Category' ), 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'work' ) )); register_post_type( 'projects', array( 'labels' => array( 'name' => 'Projects', 'singular_name' => 'Project' ), 'supports' => array('title', 'editor', 'thumbnail'), 'public' => true, 'hierarchical' => false, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'rewrite' => array( 'slug' => 'work/%project_category%', //'slug' => 'work', 'with_front' => false ), 'query_var' => true, 'has_archive' => 'work', 'taxonomies' => array( 'project_category' ) )); } add_filter('post_type_link', 'work_project_permalink', 10, 4); function work_project_permalink($post_link, $post, $leavename, $sample) { if ( false !== strpos( $post_link, '%project_category%' ) ) { $glossary_letter = get_the_terms( $post->ID, 'project_category' ); $post_link = str_replace( '%project_category%', array_pop( $glossary_letter )->slug, $post_link ); } return $post_link; } add_action('publish_projects', 'projects_default_category'); function projects_default_category($post_ID) { global $wpdb; if(!has_term('', 'project_category', $post_ID)) { wp_set_object_terms($post_ID, 'Uncategorized', 'project_category'); } } </code> Wordpress 3.2.1
|
This happened to a site a friend of mine was working on. Whats weird is that he deleted the problematic file and copied paste the code into a new php file. It seemed to do the trick. worth a shot?
|
Custom Post Type Rewrite Throws Headers Sent Errors
|
wordpress
|
Is there a way to update Wordpress without the use of FTP, but with SFTP (which uses SSH)? I've only got my server set up for SSH access (and therefore SCP/SFTP).
|
Configuration instructions in Codex on Enabling SSH Upgrade Access refer to this tutorial WordPress Tutorial: Using SSH to Install/Upgrade .
|
Update Wordpress with SFTP instead of FTP
|
wordpress
|
Ok, I have a custom post type to store list of urls. I would like to print those urls with serial numbers. I used foreach loop. <code> foreach($urls as $url){ echo $url; </code> I got n number of urls as output. But i want to print serial numbers in each url like 1,2,3 and so on. I don't want to use unordered list. Because i want to style my serial numbers too. So is there any way to print serial numbers?
|
How about: <code> echo '<ul>'; $sn_count = 1; foreach($urls as $url){ echo '<li><span class="serial-number">'.$sn_count.'</span> '.$url .'</li>'; $sn_count++; } echo '</ul>'; </code> You can then style your serial numbers with the <code> serial-number </code> class.
|
How to display serial numbers in foreach loop while querying posts?
|
wordpress
|
Is there a plugin for wordpress that can help a user to view and manage the crons that are currently schdeuled in WordPress? I have looked into Core control but doesn't allow the user to manage the cron jobs.
|
WP-Crontrol. http://wordpress.org/extend/plugins/wp-crontrol/
|
Development plugin to view and manage scheduled wordpress cron jobs?
|
wordpress
|
There is some way to get notifications when deprecated API elements are used in WordPress. How is it done? Put WordPress in debug mode (which also shows all other types of errors) or is there another method that shows only API related errors?
|
Just install the Log Deprecated Notices plugin.
|
How to receive notification of deprecated API elements and functions?
|
wordpress
|
My wordpress theme has a custom post-type. Only editors (and higher) should be allowed to use this post type. I did this with: <code> function add_capability($role,$cap) { $role_obj = get_role($role); // get the the role object $role_obj -> add_cap($cap); // add $cap capability to this role object } function set_cpt() { add_capability('editor', 'edit_cpt'); add_capability('editor', 'read_cpt'); add_capability('editor', 'delete_cpt'); add_capability('editor', 'edit_cpt'); add_capability('editor', 'edit_cpt'); add_capability('editor', 'publish_cpt'); add_capability('editor', 'read_cpt'); } add_action('init', 'set_cpt'); </code> (I think) in Wordpress 3.1 this was enough - all editors and higher had the right to use the post-type. Now , in Wordpress 3.2 only editors have the right to use the post-type. Is there a way to grant privileges to role X and higher or would I have to mention every role? Thank you! [edit] actually I found out that this never worked before. But is there another way to do it?
|
If you use the Members plugin, you can set it up like you want. It also has the possibility to add custom roles (your <code> edit_cpt </code> and so on) also a lot of plugins also work that way: <code> <?php if ( current_user_can('manage_options') ) { do_something(); } ?> </code>
|
grant a privilege for roles (for example editors) and higher
|
wordpress
|
I am using a couple of wordpress plugins for my theme, enabling them programmatically. I would not want the user of my theme to be bugged with plugin updates for these plugins, as well as viewing them in the wordpress admin panel plugins lists. Is there a way to exclude these plugins from automatic version checker and the plugins list ?
|
RE: Excluding plugins from update checks Yes you can exclude plugins from the update checker, there's no pretty solution, ie. no convenient filter to just say, here exclude these for me, but it can be done, Mark Jaquith did a blog on it a while back(and it is a relatively easy solution). <code> /** * FOR PLUGINS */ function cws_hidden_plugin_12345( $r, $url ) { if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) ) return $r; // Not a plugin update request. Bail immediately. $plugins = unserialize( $r['body']['plugins'] ); unset( $plugins->plugins[ plugin_basename( __FILE__ ) ] ); unset( $plugins->active[ array_search( plugin_basename( __FILE__ ), $plugins->active ) ] ); $r['body']['plugins'] = serialize( $plugins ); return $r; } add_filter( 'http_request_args', 'cws_hidden_plugin_12345', 5, 2 ); </code> <code> /** * FOR THEMES */ function cws_hidden_theme_12345( $r, $url ) { if ( 0 !== strpos( $url, 'http://api.wordpress.org/themes/update-check' ) ) return $r; // Not a theme update request. Bail immediately. $themes = unserialize( $r['body']['themes'] ); unset( $themes[ get_option( 'template' ) ] ); unset( $themes[ get_option( 'stylesheet' ) ] ); $r['body']['themes'] = serialize( $themes ); return $r; } add_filter( 'http_request_args', 'cws_hidden_theme_12345', 5, 2 ); </code> Source: Excluding your plugin or theme from update checks. RE: Excluding plugins from the plugins list Yes, quite possible, i wrote myself a plugin for doing just this but you're more than welcome to the code. Plugin Hider - pulled straight from my dev environment copy, so make your own adjustments as necessary. Personally i mark all the plugins i want to hide with <code> Author: hideme </code> and that covers the lot for me(nothing i'll distribute so marking them that way isn't a problem). If you try the plugin out, click the Plugin Hider link in the menu to set it up, it'll do the rest. You can of course comment out the code that creates the menu item once you've got it setup, just be sure not to forget you have a plugin that hides others(couple of times i've had myself in circles as a result). Hope that addresses your question... :)
|
Hide wordpress plugins from list
|
wordpress
|
I'm wondering if it's possible through a plugin, or otherwise, to allow people to register on my WordPress site for an account. And then through my control panel, I can manage their accounts. Here's a little backstory of what I'm trying to accomplish. My client runs a dance competition. They would like to be able to upload audio critiques, videos and media. And they'd like to be able to deliver that content just to specific accounts. For instance, a mother goes to the site and registers an account. She logs in and is able to get media related to her son or daughter from a control panel that my client uploaded specifically for them. Is this within the realm of possibility in WordPress? Does a solution already exist? And if not, if anyone could suggest a workaround that would be great. Any help would be greatly appreciated. Thanks!
|
you can achieve this very easily with simple using my plugin User Specific Content which lets you display specific content per user name, user id or by user role.
|
User Login System with File Delivery?
|
wordpress
|
I am using the latest wordpress 3.2.1. I would like to let create a new admin to do ONLY this: 1) Manage order to change the order status to (e.g. approve..reject). 2) Able to view user only without the ability to Edit or Delete. 3) Accept email notification on new registered user and new order. This would meant that when this new admin login, he is able to view only these 3 menu and All other menu will be invisible. Could anyone advice? I have tried many like the Adminimize, Admin Menu Editor, hide-admin-panels.. But all don works as it is a role based instead of user based. Should i create a new <code> admin </code> for these features above? or should i create an <code> editor </code> instead ? Then change the menu for editor.. I need your advice. thanks
|
Try this plugin: http://wordpress.org/extend/plugins/user-role-editor/
|
Show limited menu to admin
|
wordpress
|
I'm trying to restrict the number of widgets from the "wp_inactive_widgets" sidebar to maximum 10, because the widgets admin page is incredibly slow: <code> add_filter('pre_update_option_sidebars_widgets', 'cleanup_inactive_widgets', 10, 2); function cleanup_inactive_widgets($new, $old){ if(!empty($new['wp_inactive_widgets']) && count($new['wp_inactive_widgets']) > 10) $new['wp_inactive_widgets'] = array_slice($new['wp_inactive_widgets'], -10, 10); return $new; } </code> This works apparently, but the problem is that the widget instance options still remain in the database, regardless if the widget instance exists or not inside a sidebar... Does anyone know a way to remove the widget options too? I found out a solution: Edit: in certain situations it seems to remove widgets from other sidebars too, I'm not sure what's causing this... <code> if(!empty($new['wp_inactive_widgets']) && count($new['wp_inactive_widgets']) > 10){ // find out which widget instances to remove $removed_widgets = array_slice($new['wp_inactive_widgets'], 0, -10); // remove instance options foreach($removed_widgets as $widget_id) if(isset($GLOBALS['wp_registered_widgets'][$widget_id])){ $instance = $GLOBALS['wp_registered_widgets'][$widget_id]['callback'][0]->number; $option_name = $GLOBALS['wp_registered_widgets'][$widget_id]['callback'][0]->option_name; $options = get_option($option_name); // get options of all instances unset($options[$instance]); // remove this instance's options update_option($option_name, $options); } // keep only the last 10 records from the inactive widgets area $new['wp_inactive_widgets'] = array_slice($new['wp_inactive_widgets'], -10, 10); } return $new; </code>
|
Tested under v3.2.1: <code> $sidebars = wp_get_sidebars_widgets(); if(count($sidebars['wp_inactive_widgets']) > 10){ $new_inactive = array_slice($sidebars['wp_inactive_widgets'],-10,10); // remove the dead widget options $dead_inactive = array_slice($sidebars['wp_inactive_widgets'],0,count($sidebars['wp_inactive_widgets'])-10); foreach($dead_inactive as $dead){ $pos = strpos($dead,'-'); $widget_name = substr($dead,0,$pos); $widget_number = substr($dead,$pos+1); $option = get_option('widget_'.$widget_name); unset($option[$widget_number]); update_option('widget_'.$widget_name,$option); } // save our new widget setup $sidebars['wp_inactive_widgets'] = $new_inactive; wp_set_sidebars_widgets($sidebars); } </code> The above code limits the inactive sidebar to the last 10 widgets, and only the inactive sidebar. It also removes the options for the widgets that have been deleted.
|
Limit the number of inactive widgets
|
wordpress
|
I'm creating an age select menu in the admin, populated from a taxonomy of <code> age </code> . The taxonomy is hierarchical as follows: 18-25 (parent, ID 183) 18 (child) 19 20 21 22 23 24 25 26-30 (parent, ID 184) 26 27 28 29 30 I would like to only list the children (18, 19 etc) and not the parents (18-25, 26-30) etc. Currently I am using <code> get_terms </code> with the <code> parent </code> argument, but it doesn't accept more than 1 parent ID. Here's what I have so far, which shows the children from 18-25. <code> $ages = get_terms( 'age', array( 'hide_empty' => 0, 'parent' => '183', )); </code> Here's what I want it to do, but isn't supported. I have also tried it with an array but it doesn't work either. <code> $ages = get_terms( 'age', array( 'hide_empty' => 0, 'parent' => '183,184', )); </code> I see there is a get_term_children function but I'm unsure of how to use this either as it looks like it only accepts one value also. Eg: In this example it would build an unordered list but I could modify for select menu. <code> <?php $termID = 183; $taxonomyName = "age"; $termchildren = get_term_children( $termID, $taxonomyName ); echo '<ul>'; foreach ($termchildren as $child) { $term = get_term_by( 'id', $child, $taxonomyName ); echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>'; } echo '</ul>'; ?> </code>
|
This should work for you: <code> $taxonomyName = "age"; //This gets top layer terms only. This is done by setting parent to 0. $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false)); echo '<ul>'; foreach ($parent_terms as $pterm) { //Get the Child terms $terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false)); foreach ($terms as $term) { echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>'; } } echo '</ul>'; </code>
|
How to only list the child terms of a taxonomy and not their parents?
|
wordpress
|
My client has a post type that uses a lot taxonomies. I plan to put this script in a post meta box and hide the existing taxonomies. Do you know of a great wp_set_post_terms example? I want to make this: Look like this: Related functions? wp_update_term
|
Name your fields like <code> car_specs[taxonomy_name] </code> , then within "save_post" just do: <code> foreach($_POST['car_specs'] as $tax => $term) if(taxonomy_exists($tax)) // && term_exists($term, $tax) wp_set_post_terms($post_id, $term, $tax); </code> Personally I wouldn't use WordPress for a auto classifieds type of website. There are PHP frameworks out there better suited for building such sites
|
wp_set_post_terms example?
|
wordpress
|
Problem is that $today is pulling GMT from the database; I need to offset GMT by -6 hours; Have been unable to find a query with an offset like that. <code> <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $today = date('Y-m-d'); query_posts(array( 'post_type' => 'performance', 'posts_per_page' => 4, 'caller_get_posts' => 4, 'paged' => $paged, 'meta_key' => 'order-date', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'order-date', 'meta-value' => $value, 'value' => $today, 'compare' => '>=', 'type' => 'CHAR' ) ) )); if (have_posts()) : while (have_posts()) : the_post(); ?> </code>
|
Is WP set to that -6 offset you need? In that case try <code> date_i18n() </code> to generate your date instead of <code> date() </code> .
|
How do I add a timezone offset to this query?
|
wordpress
|
Is it possible for two separate blogs running on the same multisite installation to share tables in the database? By default, Wordpress adds the blog ID to the table prefix for all of the associated tables such that blog #1's posts are stored in the <code> wp_1_posts </code> table, blog #2's posts in the <code> wp_2_posts </code> table etc.. However, for my peculiar development workflow I would like to use blog #1 for public use and blog #2 for development while sharing database tables between them such that any changes made to either blog are reflected on both immediately (i.e. both blog #1 and blog #2's posts are stored in <code> wp_1_posts </code> , their users in <code> wp_1_users </code> , and so forth). Any ideas?
|
You can switch back and forth between blogs on a multisite with <code> switch_to_blog </code> and <code> restore_current_blog </code> . That should allow you to get anything you'd like and make queries as if you were actually on the other blog. Check them out: http://codex.wordpress.org/WPMU_Functions/switch_to_blog http://codex.wordpress.org/WPMU_Functions/restore_current_blog We did a lot of this with one of our recent sites .
|
Share DB tables between two blogs on the same WP Multisite installation
|
wordpress
|
I would like to start a single WordPress Blog. As I already have some experience with one provider and as it is really cheap, I would like to use the same service for my planned blog. They offer: 1 GB webspace : I will not upload many big pictures and I guess almost no audio/video files, so I guess this is more than enough PHP 5.1 and PERL scripts : PHP 5.3.6 seems to be the latest version. Although they say on their website, that they support PHP 5.1, phpinfo() tells me they actually have 5.2.17-pl0-gentoo. MySQL : according to phpinfo(): Client API version: 5.1.56. The latest MySQL -Version is 5.5.14 mod_rewrite : I guess it is enabled. This website uses mod_rewrite, doesn't it? I know that it is hosted by the provider I'd like to chose, so if mod_rewrite works there, it will work for me, too. .htaccess files may be used FTP access only! No ssh! No execution of binaries. The requirements-page of worpress states: PHP 5.2.4 or greater MySQL 5.0 or greater The mod_rewrite Apache module I would now like to know if it is easily possible to update wordpress when I only have FTP-access and phpMyAdmin. I would also like to know if it is easily possible to make backups. (I ask, because I made the experience that creating backups with MediaWiki is impossible (or at least extremly difficult and laborious) without ssh access or mysqldump . It's the same for upgrading MediaWiki )
|
I would now like to know if it is easily possible to update wordpress when I only have FTP-access and phpMyAdmin. WordPress has automatic update feature , that will do its best to perform update without you having to upload new version manually. It is not perfect, but it is quite robust and works on most configurations. If changes to database are required for new version, WordPress will perform them by itself, you won't ever need to use phpMyAdmin for that. I would also like to know if it is easily possible to make backups. There are numerous backup plugins for WordPress available, both free and paid. They differ in what is backed up (files and/or database), backup destinations (local/email/cloud/etc) and additional features (restore/migration/whatever). It will take some research to pick one for your needs (especially if you are looking among free solutions only), but this is definitely not a problem with WP.
|
Requirements for hosting a single WordPress Blog (upgrades / backups)
|
wordpress
|
Is there any way to create a simple user session on Wordpress, like a mini-membership kind of thing? Would this conflict with WP's general user sessions, or is it possible to set up a simple uesr/pass combo in your database and use this to create a sub-membership system?
|
Instead of forcing Wordpress to have a custom membership system, if you want to use your own small membership feature, then you may not have to use sessions at all. For instance, if you want to password protect a specific set of pages, you could make one page require authentication, using a username and password like you mention. Once the user has accessed this page, validated by the database of users separate from wp_users, you can use ajax to keep this "session" (or appearance therefore) alive. That way you achieve your needed functionality without having to program something that kind of goes against the nature of the Wordpress system.
|
New User Sessions in Wordpress?
|
wordpress
|
I'm building a custom front end form for my theme and I'd like to use the Wordpress TinyMCE Rich Text Editor for it. Is there an easy way to invoke it? Thanks!
|
Yes, use the code: <code> wp_enqueue_script('tiny_mce'); </code> This will include the TinyMCE javascript. Then simply use TinyMCE as you wish <code> <script type="text/javascript"> tinyMCE.init({ mode : "textareas", theme : "advanced", plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, skin : "o2k7", skin_variant : "silver", }); </script> </code> You could also opt to use a Wordpress plugin for TinyMCE, such as this TinyMCE plugin for Wordpress , which is very popular.
|
Insert Rich Text Editor in theme?
|
wordpress
|
How can I find the page which was last modified on 2011-07-20T20:48:16+00:00 other than opening every page?
|
Okay, I've got it. I looked in wp_posts table in phpmyadmin, clicked on the post_modified column to get it in chronological order, and looked for the appropriate datetime.
|
Find Page Last Modified at Certain Date & Time
|
wordpress
|
Hi I am new to wordpress. Kinda going through different themes that is available. I like on, which is Oulipo , but it doesn't have any e-mail subscription feature. I am using free wordpress hosting. I know may be this question is too silly but I don't understand how to add it. As I have heard free word press hosting don't have many features available, so I was wondering if only the allowed features are those that comes with the theme or is it customizable further? Thanks.
|
Many plugins currently available allow you to enable this feature on your site. My favorite is Jetpack Subscriptions for reasons including: Very much up-to-date, well-maintained plugin Emails sent from WordPress.com servers, so there's absolutely no load on your servers (Make sure you disable all the unnecessary modules activated by default when you activate Jetpack by WordPress.com plugin .) If you want the emails to be sent from your servers, I think you'd be better off using Subscribe to Comments or Subscribe To Comments Reloaded —whichever suits you best.
|
How do I add e-mail subscription functionality
|
wordpress
|
I'm definitely a rookie WordPress/PHP developer, so please forgive ignorance :-) Q: How do I format a date/time returned from a custom query against $wpdb? Here's the scenario: I'm trying to write a page which displays some simple statistics about my blog. One of the statistics I'm showing is the most popular posts, as determined by comment count. I've essentially got the query working, except I can't for the life of me work out how to format the post date/time the way I want to! Here the code (apologies for the long snippit): <code> <?php $queryStr = " SELECT posts.ID, posts.post_title, posts.post_date, posts.guid, author.user_nicename as author, count(comments.comment_ID) as comment_count FROM $wpdb->posts posts INNER JOIN $wpdb->comments comments ON posts.ID = comments.comment_post_ID INNER JOIN $wpdb->users author ON posts.post_author = author.ID WHERE posts.post_status = 'publish' AND posts.post_type = 'post' AND comments.comment_approved = 1 AND comments.comment_type = '' GROUP BY posts.ID ORDER BY count(comments.comment_ID) DESC, posts.ID DESC LIMIT 30 "; $popularPosts = $wpdb->get_results($queryStr); if ($popularPosts) { ?> <table class="stats_table"> <thead> <tr> <th>Post</th> <th>Author</th> <th>Posted At</th> <th># comments</th> </tr> </thead> <tbody> <?php foreach ($popularPosts as $popPost) { ?> <tr> <td><a href="<?= $popPost->guid ?>"><?= $popPost->post_title ?></a></td> <td><?= $popPost->author ?></td> <td><?= $popPost->post_date ?></td> <td><?= $popPost->comment_count ?></td> </tr> <?php } ?> </tbody> </table> <?php } else { echo("<strong>No stories!</strong>\n"); } ?> </code> This is obviously the line in question: <code> <td><?= $popPost->post_date ?></td> </code> I've tried a number of different things but none of them quite get me there. This gets me the format that I'm after, but uses the wrong date (obviously $wpdb is not returning a timestamp in the query): <code> <td><?= date('j M Y h:i A', $popPost->post_date) ?></td> </code> I also tried a solution along these lines: <code> <?php global $popPost; foreach ($popularPosts as $popPost) { setup_postdata($popPost); ?> <tr> <td><a href="<?= $popPost->guid ?>"><?= $popPost->post_title ?></a></td> <td><?= $popPost->author ?></td> <td><?= the_time('j M Y h:i A') ?></td> <td><?= $popPost->comment_count ?></td> </tr> <?php } ?> </code> But that simply repeats the timestamp for the page over and over, rather than the timestamp for each post. What am I doing wrong?
|
A much simpler method to bypass these issues is using WP_Query : <code> $popularQuery = array('orderby' => 'comment_count', 'posts_per_page' => '-1', 'author' => 1); $popularPosts = new WP_Query($popularQuery); while($popularPosts->have_posts()) : $popularPosts->the_post(); ?> <tr> <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> <td><?php the_author(); ?></td> <td><?php the_time('j M Y h:i A') ?></td> <td><?php comments_number(); ?></td> </tr> <?php endwhile; </code> Also note I've replaced your use of guid with the permalink. In some scenarios the guid of a post will not actually be the permalink, so this should never be assumed. The only exception to this is attachments. and <code> <?= </code> should be <code> <?php </code>
|
Formatting a date/time returned from a custom $wpdb query
|
wordpress
|
I'm importing posts from a Joomla v1.5 site using http://wordpress.org/extend/plugins/joomla-15-importer/ (The goal is to clone the site in WordPress then switch off Joomla) On both sites the permalink structure is /%category%/%post_id%-%postname%/ Of course, when I import I am getting a different post ID in WordPress than existed in Joomla. Can I change post ID manually in the DB after import? Aside from .htaccess file with a huge number of rules (one per article!) is there another workaround for this issue? Any comments/suggestions? Thanks, Alastair.
|
<code> wp_insert_post() </code> function in WP accepts special <code> import_id </code> field in arguments and will try to use that ID, rather than automatically generating new one. This is easy to use when writing import code yourself, but I have no idea how easy would it be to with that plugin. You could try suggesting this as a feature to plugin's eveloper.
|
How to change Post ID during import
|
wordpress
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.