question stringlengths 0 34.8k | answer stringlengths 0 28.3k | title stringlengths 7 150 | forum_tag stringclasses 12
values |
|---|---|---|---|
At the bottom of each post I need to either: Offer a link to the next post (if the next post is published); or Display the title of the next post with the date it will be published (if it's a future post) Suggestions? | Add these two where you want them to display within your single.php file. It will make the title of the post a link. <code> <?php previous_post_link(); ?> <?php next_post_link(); ?> </code> EDIT: Sorry I missed the second part of your question about future posts. Here's what I would probably do. It's not te... | Showing the next post's title, even if it's an unpublished post | wordpress |
I have a requirement for displaying a list of custom post types grouped by category, but in addition to this, each custom post is linked with a meta value (in this example lets say we have a custom meta value of "TEST1"). Basically, my goal is to display a list, grouped by category for all custom posts with a code of "... | There are a few ways you can do this. The simplest is to just get everything: posts and terms, then use some <code> array_filter </code> magic to group things. Simple example (that will only work with PHP 5.3+): <code> <?php $terms = get_terms('your_taxonomy'); $term_ids = array_map(function($t) { return $t->term... | WP Query group/order by category name | wordpress |
I managed to get my comments numbered and then to separate the comments from the pingbacks and trackbacks. The only problem I have now is that I don't want to show the title of this section (where the trackbacks/pingbacks are) unless there are any. This is the code I'm using in comments.php: <code> <div class="pingb... | I am using a helper function for that. <code> functions.php </code> <code> /** * Count amount of pingbacks + trackbacks for a post. * * @param int $post_id Post ID for comment query. Default is current post. * @return int */ function t5_count_pings( $post_id = NULL ) { $pings = 0; $comments = FALSE; if ( NULL !== $post... | Hide Trackbacks/Pingbaks if none exists | wordpress |
I get the image through wordpress built in post_thumbnail, but i see a lot of developers use timthumb for that and i don't know why! is it more flexible or something? | There are two reasons: post_thumbnail was introduced with WordPress 2.9, and many themes which used TimThumb because post_thumbnail wasn't yet available to them. TimThumb is more flexible than post_thumbnail — it gives you more options for how images are cropped , and allows for simple filters to be applied to the imag... | what is the difference between timthumb and post thumbnail? | wordpress |
I made a custom plugin for POLL . When I activate it, default icon is coming there on sidebar. I want to change this default icon. Here is my code which I wrote in init.php file. <code> add_action('admin_menu', 'mt_add_pages'); // action function for above hook function mt_add_pages() { // Add a new top-level menu (ill... | Take a close look at add_menu_page hook, it provides argument to supply with icon url <code> <?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); </code> http://codex.wordpress.org/Function_Reference/add_menu_page <code> add_menu_page( __('Poll','menu-test'), __(... | how to change default icon of custom plugin? | wordpress |
The title is the short version of the question. Here's what I need in more details... If the answer is not so simple, I would be glad if you can point me to the right direction with a tutorial or to the codex and where I can ready more about this. Inside the WP loop, and "maybe" before using "the_content();", how can I... | After some research, I came up with a solution that worked for me. It's nice because it's not using the WP Gallery (you don't need to insert a gallery into your post/page to make it work). It's awesome because you can do whatever you want inside the "images loop". Note: the 'preview' in <code> $size='preview' </code> i... | Change the way wordpress outputs images or image galleries | wordpress |
i use use this code to set slider in header with CF, how i can disable when CF is empty or set another CF key to exclude it? <code> <?php $custom_fields = get_post_custom($post_id);//Current post id $my_custom_field = $custom_fields['slider_id'];//key name foreach ( $my_custom_field as $key => $value ) echo get_n... | Less code lines with <code> get_post_custom_values() </code> <code> $values = get_post_custom_values('slider_id', $post_id); // if non-empty if($values) { foreach($values as $value) echo get_new_royalslider($value); } </code> If <code> $values </code> array is empty, nothing happens. | Conditional Custom field with foreach | wordpress |
I try to make custom taxonomies names to display with lowercase, but for some reason it doesnt work and show all taxonomy titles with big capital. Here is the code that i use: <code> $genre = strtolower( strip_tags( get_the_term_list( $wp_query->post->ID, 'genre', '', ', ', '' ) ) ); if ( is_singular( array( 'dvd... | What you are doing seems odd. You are creating and retrieving an HTML string only to strip out the HTML. Try this: <code> $terms = get_the_terms( $post->ID, 'genre' ); // var_dump($terms); $tnames = array(); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $t) { $tnames[] = strtolower($t->... | Taxonomy list names with lowercase | wordpress |
I would like to insert data into the wp_posts table with the inserted post_id in the 'guid' for a record that doesn't already exist. Below is the closest I've gotten but this doesn't work ($postarr['ID'] is equal to 0). <code> function filter_handler( $data , $postarr ) { if($data['post_type']=='ai1ec_event'){ $my_post... | Why would you need that? ID in a database is auto increment - it manages it's value itself. If your target is to set custom guid, you should update the inserted post as soon as it is created via wp_update_post right after your $post_id = wp_inserted_post($mypost); like this: <code> ...Your code above... $postid = wp_in... | Inserting post_id into guid before wp_insert_post | wordpress |
I have used Pie Register plugin to add a "Phone" field. I tried every method in the book (that google fetched for me, so far) to show it but it shows an empty array although the field is not empty and the wordpress backend shows it. Also, User Meta plugin is able to show the field with its data but I can't get it to sh... | Try this code: <code> echo get_user_meta( get_current_user_id(), 'phone', true ); </code> And pay attantion about that plugin. The plugin is not using any prefixes, so when you'll create a custom filed with same name as any WordPress user_meta, it will override this one. | Can't get custom user meta to show in header | wordpress |
I have a custom widget that I want to apply conditional logic to, depending on its parent sidebar's registered ID. For example, my theme has 6 registered sidebar widget areas. I have a custom widget that may be loaded into any of these 6 sidebar widget areas. Is there a way that I can script the widget code below in or... | The information you want is in the <code> $args </code> parameter. <code> var_dump($args); // inside your widget method </code> Look at the 'name' and 'id' array elements. Your code should look something like: <code> function widget( $args, $instance ) { extract($args); $title = apply_filters( 'widget_title', empty($in... | How to determine which registered sidebar area a custom widget is loaded into | wordpress |
I have found this: http://wordpress.org/extend/plugins/restricted-site-access/screenshots/ But, I need something a little different. Something like Jommla has for off-line mode e.g.: http://www.cloudaccess.net/joomla-2-5/89-global-configuration/207-offline-mode-joomla-2-5.html But I need to be able to access the fronte... | If I understand it correctly, you're trying to restrict access to your site while you're building it. So visitors not logged in see some sort of maintenance mode page, while logged in visitors can access the dashboard and see the front-end while they develop? I think your best route is to use a plug in. There's several... | Name and password development/offline mode plugin | wordpress |
I can add categories, I can even add a custom post type archive, but I can't add the original posts archive. It's not among the page list. I worked around this by creating a page, creating a page-pagename.php file, displaying the posts there and linking to that page, but when that page is shown, the menu item doesn't h... | Instead of finding out how to put a custom archive link in the menu (which would still be nice to know), I found the problem with my custom page template solution. To display the posts in the News page template I obviously had to alter the original query, which carried the News page record. Since the footer, which was ... | How to insert link to the default post archive into a menu | wordpress |
I have a menu in my Twenty Eleven child theme that has some hierarchical items. Twenty Eleven handles it just fine, of course, but my client likes the fancy-looking menu animation that you can see on this site . I don't need the horizontal style that shows up under the "Resources by Topic" item, just the on-hover expan... | The answer is yes. It is possible with some jquery. I think your question is still too broad. Also, asking for plugin recommendation is on the don't ask list. Id start doing some Google searches for implementing jquery in a wordpress menu, attempt and maybe ask for help with your code if it is not working. Otherwise a ... | Is it possible to animate the Twenty Eleven menu? | wordpress |
I got this error log, do you know what is this and how can i fix this? <code> [31-Jan-2013 22:01:25 UTC] PHP Warning: preg_match() expects parameter 2 to be string, array given in /home/xxx/public_html/wp-includes/formatting.php on line 608 [31-Jan-2013 22:01:25 UTC] PHP Warning: strip_tags() expects parameter 1 to be ... | You are calling <code> remove_accents() </code> and <code> sanitize_title_with_dashes() </code> with an array as first argument somewhere. This is wrong, use a string instead. Install the Debug Bar plugin and look at the backtrace to see where the broken code starts. | PHP Warning: preg_match() expects & PHP Warning: strip_tags() | wordpress |
WordPress has minimum theme template files as style.css index.php and also some other files as listed here . If the theme developer wants to build theme with less bells and whistles, what are some of the template files which should be included at minimum? There isn't any guidelines in the WordPress docex. Only thing th... | To have the theme listed: <code> style.css </code> With at minimum this: <code> /* Theme Name: Minimum Theme Description: Test Author: Test Version: 1.0 */ </code> For the theme to be functional: <code> index.php </code> <code> index.php </code> must have a post loop, so this would be the bare minimum functional <code>... | Minimum Template Files for Theme Development | wordpress |
This is a terrible user experience when I'm trying to do the most simple thing and it never works. There are many pages with "instructions" how to do this and none of the "instructions" work. Now we hate Wordpress for making the most simple thing just not possible. <code> ## Solution ## </code> This only worked when do... | WordPress admin screen -> Settings -> Discussion -> "Allow people to post comments on new articles". Uncheck it. For existing posts, go to Posts -> All Posts. You can click "Quick Edit" on any post to find the "Allow Comments" checkbox and turn them off for that post. To bulk-edit existing posts, you can select all the... | How to disable commenting from Twenty Ten theme? | wordpress |
I have the following template page. I am attempting to output all of the articles from the category 4. However I am only getting some of the posts, about 20% of them. Not sure what would be causing this. Also is there a way to use the category name in the query_posts instead of the category number? <code> <?php /* T... | For your issue regarding only returning 20% of your posts, try the following <code> <?php query_posts('cat=4&posts_per_page=-1'); ?> </code> Note: By default, 10 posts are returned. <code> -1 </code> will return all posts in the resulting set. http://codex.wordpress.org/Function_Reference/query_posts#All_Post... | Trying to query all posts in category 4 | wordpress |
I've migrated hosts for a WordPress site, and a lot of my images have the same title. I am trying to pinpoint one media file by the file name, but file name is not a column listed in Media Library. I don't want to have to wade through dozens of images with the same title trying to find the problem file name, so I can f... | Here you go, this code not only lists all filenames in Library but also allows you to sort them by name: <code> // Add the column function filename_column( $cols ) { $cols["filename"] = "Filename"; return $cols; } // Display filenames function filename_value( $column_name, $id ) { $meta = wp_get_attachment_metadata($id... | Add file name column to media library | wordpress |
For security, I changed the CPanel password for an account via WHM. There's a checkbox option that says "Sync MySQL password with account password." If I go ahead and change the password, does that create a problem for WordPress that's installed on that domain? | Actually, just found out that it doesn't. Here's the doc from Cpanel directly http://docs.cpanel.net/twiki/bin/view/AllDocumentation/WHMDocs/RestoringDatabaseAccess Sorry, now that I know the answer, this definitely isn't WordPress related. | Changing MySQL password via WHM - does this affect WordPress? | wordpress |
I just want to know whether I should roll my own theme from scratch or I should customize an existing one like twenty twelve. Reason I ask is I wanted to know whether there are any best practises I may be missing if may be missing from these themes ir I roll my own. Also I find that there is a lot of bloat even for a t... | You might look into the concept of using child themes to roll your own theme. A framework like Genesis comes out with regular updates and has a starter theme that can be quickly built upon. I would take the time to roll your own so that you can know the ins and outs of your own website. If you tweak an existing theme t... | Roll my own theme or customize an existing one | wordpress |
Essentially, I build web sites with galleries, for photographers. Up until now, gallery images have all been attached to posts and I've just pulled from the category taxonomy. This is messy if it's also to be used as a regular blog. So I've been poking around and I discovered things like if an attachment item isn't ass... | If I understand right, you need all attachments (attached or not) with specified term? <code> $args = array( 'post_type' => 'attachment', 'my_taxonomy' => 'my_taxonomy_term' ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ): while ($my_query->have_posts()) : $my_query->the_post(); // yo... | Is it possible to get all term items from a custom taxonomy regardless of post attachment status? | wordpress |
I would like to add a separator to the admin submenu section, NOT in the top level section . I'm thinking of using javascript and styling to do the job, but I was wondering if there's a more straightforward method such as that when adding stackexchange-url ("a separator to the top level menu section"). I'm still experi... | [UPDATED] This is what I had came up with. Below is a sample of how I would do it on the post menu section: (Thanks to @userabuser for the advice) <code> function add_submenu_separator( $menu_ord ) { global $submenu; // Create 'separator' array for submenu $submenuSep = Array ('<div class="separator"></div>... | Add separator to admin submenu | wordpress |
I'm the author of the Nav Menu Roles plugin that lets you display/hide menu items based on the user's role. It has come to my attention that the menu item meta does not import when using the regular WordPress plugin/tool for importing. Each menu item is essentially just a post in the database, and I've been saving the ... | The problem was ultimately with the WordPress Importer plugin. I could hack at it (and have suggested an improvement to the developers) but I am going to got around this by writing a custom Importer of my own. It isn't the most convenient (to re-upload the .XML file) but in cases where users have complex menus it is be... | Nav Menu meta failing to import | wordpress |
I have, hopefully easy question. I have my query here, which is using ACF <code> <?php query_posts(array('post_type' => 'our-clients-list', 'posts_per_page' => 1, 'order' => 'DSC', 'orderby' => 'rand','paged'=> $paged)); ?> <?php while(have_posts()) : the_post(); ?> <?php the_field('testim... | I think this should work, but I am not 100% certain on the advanced meta query for "not" a null string. That isn't normally how meta queries are used. As such, I have left the <code> set_transient </code> line commented out. I just noticed that you are trying to pull 1 random post, so you might not want to use the Tran... | Advanced Custom Fields query | wordpress |
I found this snippet in a different thread and it mostly does what I need, but I'm having trouble wrapping the individual pages this outputs with tags. All I can seem to add is a line break. I don't have a lot of experience with php so unfortunately I wasn't able to customize it to my needs. In the end I just need the ... | To wrap your titles in h2 just change <code> echo $ban_titles; </code> to <code> echo '<h2>'. $ban_titles . '</h2>'; </code> . If you want to limit number of titles displayed to 2 change <code> for($i=0; $i<count($pages); $i++) </code> to <code> for($i=0; $i<2; $i++) </code> . Hope it helps, PHP is no... | How can I get an tag to wrap each ancestor that gets outputted in this condition? | wordpress |
I have been researching this for over a week now. I've tried a few tutorials on custom rewrite rules and custom post types, but I'm still not sure which direction I should go in for making this happen. And it absolutely has to happen. This is a large client who needs to retain the same link structure that is coming fro... | So in the end, here is what I've concluded. Doing the above is doable if you write or use a migration script that transposes the MT3 or 4 data into WP mappings...such as Title, Primary Category, etc. So assuming that all works fine, you then concatenate the category name separated by hyphens onto the title making it th... | Custom rewrite rules for /pastissues/%category%-%postname%.html | wordpress |
Im trying to get a list of post in a category with this: <code> $category = get_the_category(); $args = array( 'post_type' => array('post', 'entrevista'), 'cat' => $category[0]->term_id, 'post__not_in' => array(get_the_ID()), 'ignore_sticky_posts' => 1, 'posts_per_page' => -1 ); $queryScience = new WP... | You have to call <code> the_post() </code> within your loop, otherwise you'll output the first post in an infinite loop, as <code> have_posts() </code> will always be true. <code> $queryScience->the_post(); </code> Also, you don't need <code> wp_reset_query() </code> with <code> WP_Query </code> , <code> wp_reset_po... | new WP_Query all post in a category inside the loop | wordpress |
In functions.php of a theme makes a call to <code> show_admin_bar(false) </code> which hides admin bar in front end: <code> if (!is_admin()) { wp_deregister_style( 'bp-admin-bar' ); if ( function_exists( 'show_admin_bar' ) ) { show_admin_bar( false ); remove_action( 'bp_init', 'bp_core_load_buddybar_css' ); } } </code>... | First off: This Theme is so doing it wrong. One should not simply stuff plain calls in functions.php files. Those should be wrapped and hook. Best to <code> after_setup_theme() </code> . You could btw try the same hook. | How to override a function call in functions.php? | wordpress |
I'm using a custom theme not developed by myself that seems to have disabled/ or doesn't have the function for any and all Shortodes, whether its a WordPress shortcode or a plugin shortcode. I mostly need this function to work via a plugin generated shortcode. Ive checked several things to see what is causing it but ha... | So I finally found a solution!!! After many weeks of searching and trying different solutions, it was just a matter of removing "get_" from a reference of "the_content" in my page.php I changed this <code> <?php function sup($text){ $true = preg_replace('#(\d+)(st|th|nd|rd)#', '$1<sup class="super">$2</sup&... | All shortcodes not working on custom theme | wordpress |
I use WP_DEBUG_LOG in my development environment and have no issues with debug.log being in the wp-content directory. Sometimes I turn on WP_DEBUG in production when I need to debug something, and I still want to use the log but would like to redirect it to something outside my web root. Is this possible using WP_DEBUG... | It turns out that all WP_DEBUG_LOG does is: <code> ini_set( 'log_errors', 1 ); ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); </code> So, if you want to change the log location for WP_DEBUG_LOG in a plugin or theme, stackexchange-url ("webaware's answer") is best. If you just want to have it changed within <cod... | Is it possible to change the log file location for WP_DEBUG_LOG? | wordpress |
I've got some jQuery that interacts with items on the post and page editor screens. However, the script is also loading on other admin screens that are driven by post.php Is there a way to target the post/page editor screen exclusively? I'm currently using: <code> global $pagenow; if( 'post.php' == $pagenow ) { //jQuer... | Use the WP_Screen object to tell where you are at in the admin instead. Much more convenient. <code> $screen = get_current_screen(); if ( $screen->id == 'edit-post' ) { // you're on the posts screen } </code> Note that you have to wait until at least the admin_head hook to run for the current screen to have been det... | How to isolate code to the post edit screen | wordpress |
I am playing around with template hierarchy. I have uploaded stock 2012 theme and deleted page.php and single.php. I found that when I visit a blog post and click the the post reply link to leave a comment, the comment form doesn't show. So I copied comments_template() function out of single.php and pasted it into cont... | Looks like you're trying to display comments for a single post that has comments disabled. You should find <code> if ( comments_open() ) </code> statement just one line below. Paste your code there and it will work just fine: <code> <?php if ( comments_open() ) : ?> <div class="comments-link"> <?php comm... | explain why is_single doesn't work | wordpress |
How to update avatar in buddypress programmatically? I have a script, which gets the image url and I want to update the url in the database, so that that image will will be avatar of the user. | WordPress does not save the value of the avatar image in any database. It looks in the file system for avatar image and displays it on the website. So, I am planning to download the image to the server, which is running the WordPress (BuddyPress). I need to create a directory with the name same as user ID, in the direc... | How to update avatar in buddypress programmatically? | wordpress |
I am looking for something really simple(?). I am using WordPress as a CMS. I created a new page in which I added a form (questionnaire). Inside WordPress' database (the same database in which all WordPress data are), I created a new table called "ExampleTable". Now I have 2 questions: 1) How can I insert data from the... | It is OK. And you can access this table with standard way, throught wpdb To insert data to your table use this code: <code> global $wpdb; $wpdb->insert( 'exampleTable', array( 'column1' => 'value1', 'column2' => 123 ), array( '%s', '%d' ) ); </code> To breafly explain what this code mean. WordPress sanitizes v... | Accessing + retrieving custom database in WordPress | wordpress |
i asked here in WordPress first and next asked stackexchange-url ("there") in webmasters Stack but i think here is very useful for WordPress users but close my question. I'm using the similar posts plugin http://wordpress.org/extend/plugins/similar-posts/ , but I want the similar posts in all over the internet. is ther... | You won't find a Wordpress plugin to do that - you need to use http://www.copyscape.com or something similar; Good luck getting people to remove your content though, most of them will be automatically generated heaps of junk. | similar of my posts in all over the internet sites and blogs | wordpress |
So I have setup a custom post type 'products' and custom taxonomies / categories 'defence' 'law & enforcement' and 'Commercial'. I have using the following conditional to set some specific css and the correct banner for a product: <code> <?php if (has_term( 'defence', 'productcat', $post->ID )) { ?> </code... | Ok, to work around this and do what i need to do i installed a plugin (Custom Post Type Permalinks by Toto_unit) to add custom post types and custom taxonomies to my permalink structure. For my conditionals i'm using $_SERVER['HTTP_HOST'] == to check the current url. Hopefully this helps someone else. | Custom Taxonomy conditionals | wordpress |
I want to limit registration based on the domain associated with their email address. I was looking at the <code> user_register </code> action hook, but it fires after the user is already inserted, which, although it could be hacked into working, is less than ideal. I want to preempt rather than retroactively remove in... | You're looking in the wrong place. When a user first attempts to register, their username and email is processed and sanitized inside the <code> register_new_user() </code> function in <code> wp-login.php </code> . This is where you want to do your filtering. Before the user is created, WordPress will pass the sanitize... | Can I hook into user registration *before* a user is created? | wordpress |
Is there a way to protect all RSS feeds from my WPMU install without blocking access to the individual posts or pages? Essentially I want anyone to have access to individual pages, but the aggregate list should require an auth code. Anyone have advice or a direction to point me in? | Based on the comments you can have several options. The easier one is to check for a special parameter at the URL, this assume you provide them the URL, and they configure it manually in whatever software the use to fetch the feed. For the example you give them the URL as mysite.com/feed?pass=123456 where pass is the s... | Require authorization for access to RSS feeds, but leave posts public | wordpress |
I have a custom taxonomy set as a "splash" on my front page, I would like to only display the latest one of these taxonomies as a splash, and any older ones to be returned to the loop and displayed as normal. My code atm below displays the splash fine, but reproduces the splash again in the loop for some reason: <code>... | You should save the ID of the first post in a variable (e.g $splash_post_id) and in the next loop, use <code> "post__not_in" => $splash_post_id </code> , in the <code> $args </code> array. <code> $args = array( 'post_type' => 'post', 'posts_per_page' => '1', 'order_by' => 'date', 'order' => 'DESC', 'tax_... | Only display latest custom taxonomy post | wordpress |
I am currently working on a theme that uses the Wordpress Customization API and I need to remove some pre-existing sections from the customization preview pane. Is there somewhere like a global variable holding an array of the sections perhaps (in true Wordpress style) I can unset the navigation section in particular? ... | Just call <code> remove_section </code> method of the <code> $wp_customize </code> object: <code> add_action( 'customize_register', 'wpse8170_customize_register' ); function wpse8170_customize_register( WP_Customize_Manager $wp_customize ) { $wp_customize->remove_section( 'section-id-to-remove' ); } </code> | How to remove a settings section from the Theme Customization API preview pane? | wordpress |
I've been handed over a design to translate into WordPress plugin & theme. My question is regarding building a custom comment form. The design used some custom scripts on the comment submit button. It handles 'submitting...' button state, animations, and checks. And it uses an anchor tag <code> <a> </code> wi... | This is hard. Output buffering could solve that: <code> add_action( 'comment_form_field_comment', 'ob_start' ); add_action( 'comment_form', 'wpse_83898_replace_submit' ); function wpse_83898_replace_submit() { $html = ob_get_clean(); # do some magic echo $html; } </code> Just an idea, not tested. | Deep customization of the comment form? | wordpress |
I currently manage a multisite installation with 7 member blogs. We need to produce a combined RSS feed of news from all 7. Currently we use Feedwordpress to syndicate 6 blogs into blog number 7. This isn't working out because we're duplicating content in the db. Ideally I need a cached feed to reduce server load (the ... | Here's one option we use for a high volume global RSS feed. It's worked out really well for us and has lower load times than trying to do some runtime combination. http://premium.wpmudev.org/project/post-indexer/ http://premium.wpmudev.org/project/recent-global-posts-feed/ | Generate aggregated feed from member blogs | wordpress |
I want to AJAX post content into a pop-up div when I click on the post / page link. I have come up with the following code: Relevant HTML / PHP: <code> <ul class="links"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>">&... | Your code is not clear as it is out of context but it looks to me like you are loading your posts pages over AJAX through their normal URLs-- URLs like <code> http://example.com/this-is-a-post/ </code> or <code> http://example.com/2012/12/01/this-is-a-post/ </code> . The drawback to doing that you are loading the entir... | AJAX post into pop-up div | wordpress |
I'm using WordPress Multisite. When I use <code> wp_logout_url() </code> , I get redirected to the login page but somehow I end at a different login page without any styles applied <code> <a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a> </code> That's the only logout function I'm cal... | If you want to redirect to the page you're currently on use: <code> wp_logout_url( $_SERVER['REQUEST_URI'] ); </code> or <code> wp_logout_url( get_permalink() ); </code> Or if you want to redirect to another site use the allowed_redirect_hosts function. | Logout/login redirect CSS issue | wordpress |
For both Twenty Twelve 1.1 and a child theme based on Twenty Twelve, widgets cannot be added. If I go to appearance > widgets, there is no widget area to drag widgets into. I have reinstalled the latest Twenty Twelve theme, and switched to it, but the issue remains. Wordpress v3.5.1 | Your most likely having an issue with the plugins. These types of problems are extremely hard to diagnose. I had a similar problem with the Wordpress theme Arjuna-X where it was loading it's own modified JQuery library that was only breaking the switching of "Visual" and "HTML" in the post editor. Took me days to figur... | twenty twelve theme widgets not working | wordpress |
I am working on a function set that will add a piece to each custom post type on a site. Since I won't know what CPTs are registered, I wrote a function to get them all (simple). However, I now need to create a function for each value in an array (a small settings page) to properly finish this off. here's my array exam... | Can you use the __call PHP class functionality? http://www.php.net/manual/en/language.oop5.overloading.php#object.call You could use __call in your class and call your function for grabbing the page types and check them against the $name (first) argument and running custom code against it. For instance: <code> __call (... | create functions based on array values | wordpress |
I have a simple auto log in hook that looks like the following: <code> function auto_login() { if (!is_user_logged_in()) { //Removed some code for brevity. $user = get_userdatabylogin($domainName); if ($user != null) { //Set the auth cookie. wp_set_auth_cookie($user->ID, false, null); //Set the current user (this wi... | Maybe it is too late to hook on init. Try set_current_user or some earlier hook. List is here: https://codex.wordpress.org/Plugin_API/Action_Reference | Auto log in hook is requiring a page refresh | wordpress |
I'm trying to build new wordpress plugin. Additional to the default wordpress categories box in the publishing screen of posts and pages, I want to add another box for custom taxonomy categories , How can I do that ? | All what you need to do is just pass required post types as array in the second parameter for <code> register_taxonomy </code> function call: <code> add_action( 'init', 'wpse8170_init' ); function wpse8170_init() { register_taxonomy( 'my-taxonomy', array( 'post' ), array( ... ) ); // or call this function if your taxon... | How can I add the custom taxonomy categories to the posts and pages? | wordpress |
I need to show the pedigree or lineage of an animal in my wordpress site. Currently I have the animals set up as custom post types, with data inserted using the amazing Advanced Custom Fields plugin. I can't really find any good plugins for this that do it well, especially those that can output standards compliant HTML... | From Wikipedia Animalia is the taxonomic kingdom comprising all animals (including human beings). From the Codex Taxonomy is one of those words that most people never hear or use. Basically, a taxonomy is a way to group things together. For example, I might have a bunch of different types of animals. I can group them t... | How to show animal lineage/pedigree in WordPress? | wordpress |
I'm trying to access widget information saved in the <code> wp_options </code> table. I printed it out: <code> add_filter('the_content', function(){ $res = get_option('widget_my_widget'); print_r($res); }); </code> And it outputted this: <code> Array ( [2] => Array ( [title] => asian kung-fu generation [descripti... | It seems that the index value goes incrementing and we add/remove instances of the widget. To make sure the correct data is grabbed, I can only think of checking inside the widget data itself through some control variable, something like: <code> Array ( [2] => Array ( [title] => asian kung-fu generation [descript... | Accessing widget information | wordpress |
I have custom type posts that I need to separate by year as the posts are entries in an annual contest. Would it be better in the long run for efficiency of queries, speed, etc to simply use the built in post date or set up a custom taxonomy to group these posts into years? I notice that post_date is stored in the wp_p... | I can't see any practical reason to use a custom taxonomy here. You can already query posts by year using OOB query and archive stuff (see this Codex article about the "year" WP_Query parameter, and this one about the "yearly" mode for wp_get_archives() ). If you're asking purely about performance, I'd consider this ki... | Better in the long run to use post date or custom taxonomy to sort/separate posts by year? | wordpress |
Being totally new to WordPress and (extremely) rusty with PHP, I'm having a difficult time figuring out how to add the Social Media Widget to my site's header. I'm using the Twenty Eleven theme, as I need the site to have no sidebars. Ideally, I'd like the social media icons to show up either above or below the site se... | You can throw a widget anywhere into your template (if you do not want to use sidebar drag + drop) by calling <code> the_widget </code> . In your case you would need to put this in the appropriate spot (maybe header.php or menu.php), you will have to figure out where you want it. <code> the_widget('Social_Widget ', $in... | How do I get the Social Media Plugin to show up in my Twenty Eleven child theme's header? | wordpress |
Given a site with 100 posts, where an unspecified number of posts are manually written, and the rest are created using the WordPress importer, how would I programmatically identify the posts imported without having access to remote sites or the original import file? E.g. was this post created by the Importer tool? | Two things I could imagine: Check the <code> post_modified </code> value. Maybe import creates a definitive timestamp that you could use. You'll still have to save the import date somewhere so you can check against it. I do some post importing via a stream/HTTP response (this is not the native importer). During the imp... | Identifying Importer Posts | wordpress |
I am working on a wordpress site that usually allows three levels of nested comments. But I would like for (at least) one specific page to allow only one level of comments => no nesting. How can I do that? edit: requested clarification: I can identify this page by the used page-template. | Please reference the Codex entry for <code> wp_list_comments() </code> . This function includes a <code> 'max_depth' </code> parameter in its args array. On the specific page in question, simply call: <code> <?php wp_list_comments( array( 'max_depth' => '1' ) ); ?> </code> If you need more specific help, pleas... | different levels of nested comments per page | wordpress |
I need to filter posts by a custom field value. My specific example: User browse to products > category 1 > subcategory A. ALL "subcategory A" items (products custom post type) are displayed as default by date. Each item in subcategory A has a custom field "size". User can select the size with a dropdown menu and posts... | Edited according to first comments and Pastebin code: <code> <?php /* You can also leave 'action' blank: action="" */ ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="my_size" id="size" class="postform" onchange="submit();"> <option selected="selected">Cho... | Filter results with custom field values and dropdown | wordpress |
I have an image that I've uploaded through the WP media library. I can see this image in my uploads folder via ssh/ftp. I cannot see this image if I put the URL in my browser, like www.site.com/files/image.jpg (It's a multisite and all uploads go into individual folders rather than be separated out by months). In WP, t... | It turned out to be an .htaccess rule put in by a coworker. It was supposed to target just some .pdf files but the rule wasn't written strict enough. So that was a fun few hours spent on wild goose chases. | Image uploaded in media library, can only see it when I using the WP Edit Image feature. 404 when trying to view in browser | wordpress |
Is there a function that simply returns the current "page type" instead of using is_page(), is_preview(), is_single(), is_archive(), etc? For example: I can find the current "post type" but I can't find it's corresponding "page type". | You need your own helper function which will return you what you need. It could be like this one: <code> function wpse8170_loop() { global $wp_query; $loop = 'notfound'; if ( $wp_query->is_page ) { $loop = is_front_page() ? 'front' : 'page'; } elseif ( $wp_query->is_home ) { $loop = 'home'; } elseif ( $wp_query-&... | Return current page type | wordpress |
I need add a rewrite rule in my plugin, and distribute it with my code. All works fine if I put the rule in the .htaccess in the WordPress root folder, but I need distribute the plugin with my rule. I try to put a .htaccess inside the plugin folder and try to use the add_rewrite_rule function but doesn't works either. ... | NOTE: WordPress Rewrite API is not the same as Apache Rewrite module. WP Rewrite API doesn't redirect a request to another URL, it used to parse current URL and fill <code> query_vars </code> array. The issue is in the second parameter of you <code> add_rewrite_rule </code> function call. It has to start from <code> in... | Add rewrite rule in plugin: with .htaccess in plugin folder or using WordPress functions | wordpress |
I receive the message: Preview mode could not be disabled. Please run chmod 777 /wp-content/w3-total-cache-config-preview.php to make the configuration file write-able, then try again. I have chmodded the file to 777 and the error message remains. | W3 Total Cache plugin basically removes <code> w3-total-cache-config-preview.php </code> , when disabling the preview mode. In <code> /wp-content/ </code> folder, please check if you have a file named <code> w3-total-cache-config.php </code> . If it exists, please compare it with <code> w3-total-cache-config-preview.ph... | W3 Total Cache "Preview mode could not be disabled" | wordpress |
I am playing around with the <code> autoload </code> column of the <code> options </code> table. I didn't find much information about how the autoloaded values are used. I tried a <code> print_r($GLOBALS) </code> and saw that the autoloaded options are stored in <code> $GLOBALS['wp_object_cache']->cache['options']['... | I didn't find much information about how the autoloaded values are used. There is no special case for autoloaded options, they are used in the same way as else regular options, but lets figure out what <code> autoload </code> column of the <code> options </code> table means. This column determines do we need to fetch a... | Performance with autoload and the options table | wordpress |
I want to be able to display 3 posts from the same category on my index.php page, but due to the way my site's HTML/CSS is coded I'm having some difficulty understanding the correct way to go about doing this using a loop (as the code for the divs being used are not the same for all three sections, it's using different... | The WordPress query object has an internal counter, <code> current_post </code> , which you can use to check the position of the post in the loop you are currently outputting, whether it's the main query <code> $wp_query </code> or a custom query you create via <code> WP_Query </code> . The important thing to remember ... | Display 3 posts with different HTML markup using a loop | wordpress |
I have two kind of post types in my WordPress website: "Articles" which is the classic post type "Breves" which is a custom post type I want them to share the same standard categories and post tags so this is how I created the "Breve" custom post type as a plugin: <code> function breve_register() { $labels = array( 'na... | The admin menu is kind of a pain to work with, it's not very flexible and is in need of an overhaul. See this ongoing ticket on the subject. What you can do is use the <code> remove_submenu_page </code> function to remove the category and tag submenu pages, then add them on the top level via <code> add_menu_page </code... | Custom post type, taxonomy and admin bar | wordpress |
We have a web application that we run inside of WordPress in order take advantage of WordPress's authentication. To make this work, we created a template type for our application that simply includes our application's start page. While a little bit of hack, this works great, except for once aspect - all the relative UR... | <code> ../directory1/directory2/directory3/css/stylesheet.css </code> should get you there if I am reading your description accurately. However, I would be very cautious using relative links in WordPress. They do not always work the way you'd expect because a lot of 'directories' don't actually exist. They are fabricat... | Handling URLs in WordPress application | wordpress |
I use <code> save_post </code> hook, and I have to know inside this hook function, whether it is a publishing ( <code> draft to publish </code> ) or is it an updating, like <code> publish to publish </code> or <code> draft to draft </code> . Is there a way to check it? I can not use <code> draft_to_publish </code> hook... | There are hooks specifically for this, actually. The codex has a pretty good overview . Essentially every time WordPress saves a post (which it does through <code> wp_insert_post </code> ) or alters the status of the post, it calls <code> wp_transition_post_status </code> which looks like this: <code> <?php // in wp... | How to check what kind of saving it is? | wordpress |
I installed the plugin Advanced Custom Fields and created few custom fields , but I'm not able to add any content in it. How is this done? | Within Admin under 'Screen Options' tab, make sure 'Custom Fields' is ticked. Then below your Post you should find your Custom Fields area. From here, select the custom field from the dropdown and add content in the value field on the right. Hope this helps. | Custom fields issue | wordpress |
I was hoping to get some help with how I organise posts in WordPress. I have 2 Custom Post Types called 'Places' and 'Events'. In the Admin, I'd like to be able to create a 'Place' post and associate multiple 'Events' posts to this. So perhaps inside an 'Event' post, I can select a 'Place' post from a list to associate... | Three methods: Don't use taxonomies at all, just store the ID of the associated posts as post meta Create a taxonomy, and remove the ability to edit/delete/create terms. Then use automation to catch the hooks for the creation, editing, and deletion of Place posts, and create/edit/delete the associated terms in the taxo... | How do I do this with WordPress? Taxonomies? | wordpress |
I want to add a menu that belongs to parent multisite blog to all child-blogs. I need the menu displayed in all child-blogs, I mean the same menu on all multisites blogs. How I can do that? | Well, thanks to @toscho ... For your help I found a way to achieve show the primary nav that belongs to parent blog to all child blogs: <code> /** * Plugin Name: Network Primary Nav * Network: true */ add_filter( 'wp_nav_menu_objects', 'network_primary_nav', 100, 2 ); function network_primary_nav( $menu_items, $args ) ... | How to add a menu that belongs to parent blog to all child-blogs? | wordpress |
I have a WPMU instance that works less like a network of blogs and more like a holistic application. I'm needing to do a check and see if 3 pages with the slugs 'home', 'login', and 'password' exist. If not, I need the system to generate them automatically. If it does, I need the system to ignore. Right now I have the ... | I think you want: <code> if( get_page_by_title( 'home' ) == NULL ) create_pages_fly( 'home' ); </code> Your original <code> if </code> condition said if the page exists (does not equal NULL), then create the page. Also, the 2nd argument should be a string, though it doesn't really matter in this case since it'll just d... | Create pages automatically if they don't exist | wordpress |
At the moment I'm doing <code> add_filter("manage_edit-comments_columns", function($columns) { unset($columns["author"]); $columns_one = array_slice($columns,0,1); $columns_two = array_slice($columns,1); $columns_one["user"] = "User"; $columns = $columns_one + $columns_two; return $columns; }); add_filter( 'manage_comm... | There is no filter for this column. So answer is 'No'. WP_List_Table search for method column_{something} inside class of Lister. Comments List class has column_author. So kill this column, and create filter as you do now. | Hook to edit an column on comments screen? | wordpress |
I have a simple function that adds a couple of pages to the users website when they activate my plugin. Actually there are many plugins out there that generate custom pages for the user, plugins like woocommerce do this. Question: If the user does not have a menu assigned to their theme, many times the theme reverts ba... | If you don't want them to ever be listed (using wp_list_pages at least) then you could hide them using a filter <code> add_filter('wp_list_pages_excludes', 'my_page_excludes'); function my_page_excludes() { // the array should contain the page ids you want to exclude return array(1,6,7,12); } </code> This will stop the... | remove auto generated pages from the menu? | wordpress |
I have scripts for various little tools I have made using some js and html. I want the js to load only on specific single posts in side a specific category. I have tried the following code and it does not work. I removed the "if" statement and the script does run and work so it's a matter of fixing the if statement. He... | Inside your theme's <code> functions.php </code> add something like this: <code> function my_conditional_enqueue_script() { global $post; if (is_single($post->ID) && in_category('mouse', $post->ID)) { wp_enqueue_script('mousescript'); } } add_action('wp_enqueue_scripts', 'my_conditional_enqueue_script'); ... | How to enqueue script based on post category? | wordpress |
I'm creating a plugin that uses a custom post type. I do not want to make a custom template for viewing the posts and discovered I can add a filter for the_content to include my custom fields, this works great. However, I don't want visitors to navigate the custom post types with the previous next navigation. It there ... | Try this: <code> function remove_link( $format, $link ) { return false; } add_filter( 'previous_post_link', 'remove_link' ); add_filter( 'next_post_link', 'remove_link' ); </code> It should work if the theme uses <code> next_post_link() </code> and <code> previous_post_link() </code> . Cheers | Is it possible to remove next-post / previous-post with out creating a custom template? | wordpress |
I'm using 3.5.1 and WP UI plugin. When i create a post, add automatically Read More button. Like this: <code> <p class="wpui-readmore"><a title="Read more from NEWS" href="http://mysite.com/my-text/" class="ui-button ui-widget ui-corner-all">Read More...</a></p> </code> But i cannot use Read Mor... | It sounds like your theme is using the_excerpt() instead of the_content() when displaying the post. If you want to display the full post you'll need to edit your index.php file to use the_content() instead. | Remove read more | wordpress |
I'm trying to create a custom route for a WP Mutlisite network. If you're familiar with WPMS, you know that the db tables for each blog on the network begin with something like <code> {prefix}_2_ </code> . Normally, visiting <code> mysite.com/blogname </code> is what takes you to the blog's homepage. What I'd like to d... | Maybe you are looking for a URL Rewrite ( <code> .htaccess </code> ) answer, but a simple solution is giving the site name its ID. Not related, but useful: add a column with the site ID in the Sites screen ( <code> /wp-admin/network/sites.php </code> ). Drop the plugin in the <code> mu-plugins </code> folder. <code> &l... | WP Multisite - How to create a custom "router" for blog prefixes? | wordpress |
I would like to write my post in one of the my 3 blogs and the same post will be published in the other two blogs. How can I do that? | You can hook on <code> save_post </code> or <code> publish_post </code> hook in each post and publish in other blogs. You must use the function <code> switch_to_blog() </code> to switch in other blog and then use <code> [wp_insert_post()][2] </code> to save a post inside this blog; do this for each blog. Alternative is... | How to save the same post in multiple blogs? | wordpress |
I have a custom page template where I would like to load some javascript. I suppose I could always include the javacsript in the actual file, but that seems ugly. Is there any way to identify if wordpress is loading my custom-page.php file so I can enqueue the script only on that page? It should work dynamically, so ch... | You can use <code> is_page_template </code> to check if you template is being used and load your scripts based on that ex: <code> add_action('wp_enqueue_scripts','Load_Template_Scripts_wpa83855'); function Load_Template_Scripts_wpa83855(){ if ( is_page_template('custom-page.php') ) { wp_enqueue_script('my-script', 'pat... | How to load javascript on custom page template? | wordpress |
I am looking for a way to write a condition for a subpage...in other words <code> if </code> we're on the subpage "duck" then do something... <code> if </code> not do something else. I found some code I thought would work, but it shows up on all of the pages under a given parent page, not just on its individual page...... | I don't know what I was thinking earlier...I guess somehow I was thinking that <code> is_page </code> wouldn't work for my child page, but I was over-thinking...this is my final code: <code> <?php if (is_page("duck")) { echo "do something"; } else { echo "something else"; } ?> </code> I know, I know it's so simpl... | Subpage Conditional | wordpress |
I tried incrementally adding in my widget area to the masonry layout (PHP below) it appears but I cannot get it included into the masonry like the other blocks. <code> $counts = 0 ; $addin = get_sidebar('masonry'); foreach ($posts as $post) : setup_postdata($post); $counts++; ?> <div class="box"> <?php if($... | Figured it out! Here's the get_posts method to add a widget (or any content into a masonry layout at the "$counts" number you define) <code> <div class="arrange"> <?php $args = array( 'posts_per_page' => 10000, 'offset' => 5, 'orderby' => 'post_date', 'order' => 'DESC', 'exclude' => 'none', // '... | Adding Widgets to Masonry Layouts Correctly - jQuery &&|| PHP | wordpress |
I create a new theme. One of my targets is to enable the admin to add unique text (html code) to unique table which the theme will automatically create (I mean something like <code> wp_myhtml </code> ). My questions are: How to define that the theme will create a new table only at the first time the admin activate it (... | I'm adding this as an answer, even though it doesn't strictly answer the question you've asked, but it is a means to achieve what you're after. As I mentioned in my comment, you can use a custom post type and post meta data to store this data, you don't necessarily have to use the WordPress provided UI to manage the da... | How to using custom DB tables | wordpress |
I've got more than a few metaboxes being used with a custom post type and I'm running into an issue where my data is not being saved as expected. Here is the relevant part of the code, and its within a function hooked to <code> save_post </code> . <code> // Loop through our custom metabox post data foreach ($_POST['pro... | I know save_post is called twice when a post is saved. The fact that die() solves your problem indicates that the second call is undoing the first, perhaps? save_post will also be called on autosave, so you might want to eliminate those too. | Saving custom metabox data with a twist | wordpress |
I have a issue with wp_get_archives because it breaks my Html5 validation. Inside validator I get this message: Bad value archives for attribute rel on element link: Not an absolute IRI. The string archives is not a registered keyword or absolute URL. My archive links looks like this: http://robertpeic.com/wordpress_te... | I would just remove the <code> wp_get_archives() </code> call from the document head altogether. Why even have it there? Otherwise, this isn't really WordPress -specific. <code> rel="archives" </code> is valid for <code> <link> </code> tags in HTML5 . | wp_get_archives breakes Html5 validation | wordpress |
I've been asked if I can add an option for "Today" and "Yesterday" to the date filter dropdown at the top of the post list in the WordPress admin view. (This is the list that shows recent month/years.) Does anybody know any filter or action hook I could use to add a couple of options to this list? People have discussed... | Man, you can not hook to that filter at all. I've followed the source code in order to find out whether there is any posibility, but unfortunately, there isn't. The function which generates select months_dropdown does not contains any filter at all. months_dropdown function is a part of a WP_List_Table class and it's d... | Admin post list - adding an option to the date filter dropdown | wordpress |
I read an article (which I didn't save) that argued you can improve the performance of your site by changing all file paths to full paths, so for instance, instead of <code> <img src="<?php bloginfo('template_directory'); ?>/images/headers/image.jpg" /> </code> we go with <code> <img src="http://domain.c... | This is nonsense. Almost all URL getters are a result of <code> get_option() </code> , eg. <code> get_option('stylesheet_root') </code> , <code> get_option('template') </code> and so on. These options are loaded very early during the request, they are cached and not fetched again. Since the options are fetched anyway, ... | Optimizing site speed by localizing paths | wordpress |
After researching a lot I found that there are quite a few very common issues with the "Yoast SEO plugin" that haven't been resolved yet. I also ran into those issues (which is why I was researching) and strangely enough there are no solutions for many of those issues yet, although they are so common. Many users of the... | You have two titles because Yoast adds an og:title tag, and then you add another one with your own code, what's unexpected about this result? so remove the one you add with your code, problem solved. Facebook's Debugger doesn't like your page because you have two og:url tags, one added by Yoast, then another added by y... | Yoast SEO Plugin: Double Title isse | wordpress |
I'm transitioning all my query_posts queries to get_posts after a lot of research about how bad it is for performance. My solution is get_posts but working with it is confusing me. Here is what I have: <code> $posts = get_posts('showposts=-1&offest=10&post_type=any'); foreach ($posts as $post) : ?> <div c... | How do I get dynamic parameters into the array,... This example from the Codex demonstrates that: <code> $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; $sticky = get_option( 'sticky_posts' ); $args = array( 'cat' => 3, 'ignore_sticky_posts' => 1, 'post__not_in' => $sticky, 'paged' => $pag... | Working with get_posts parameters/arrays/strings | wordpress |
I have a <code> new WP_Query </code> that I use to generate a custom loop and display a set of posts. One of the things the query does is provide pagination. Before I display the queried posts though, I'd like to get a list of all the tags for the posts found. I know I can do this by looping through each of the posts a... | I don't think that is possible. The SQL query performed by <code> WP_Query </code> returns only the post objects (and perhaps some metadata), while the tags resides in a different table. When looping through the returned posts in templates you usually put <code> the_tags(); </code> or something similar in your template... | Given a WP_Query, how can I get a list of tags? | wordpress |
I'd like to manipulate a WordPress website from another program/website. IS there an API already written that provides access, and authentication, to do this? Ideally, I'll be using a multi-site wordpress instance and I want an outside program to add new sites, send config options to plugins, etc. | WordPpress platform provides XML-RPC support which you can use to maintain your WP site. You also enable to extend functionality of build in xml-rpc methods to use it for your needs. | External WordPress API | wordpress |
I have a fresh 3.5.1 installation - default theme, no plugins. Running HTTPFox on Firefox shows that after a GET-request of any given page in Wordpress has finished loading, a GET-request is sent for the <code> rel='next' </code> page: <code> <link rel='next' title='Next Page Title' href='http://www.domain.com/next-... | This isn’t WordPress, it is Firefox’ Link prefetching . You can turn it off. Serve those requests nothing: <code> # Serve Firefox' prefetch requests an empty page RewriteCond %{HTTP_X_MOZ} ^prefetch$ RewriteRule ^ - [L,R=204] </code> | Wordpress tries to load "next page" after done loading current page | wordpress |
I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see frontend requests go through "/wp-admin/". No practical reason, just looks ugly IMO.) So I've simply copied admin-ajax.php to t... | You could just use a RewriteRule to your .htaccess above the regular permalink rewrite rules: <code> RewriteRule ^ajax$ /wp-admin/admin-ajax.php [L] </code> Now send your AJAX requests to <code> example.com/ajax </code> , and never miss core changes to that file after upgrades. | Adding admin-ajax.php to the frontend. Good or bad idea? | wordpress |
I'm writing a custom plugin that is initialized at <code> init </code> . This plugin is trying to query for some custom post types already stored in the DB. Here's my code: <code> $args = array() $myposts = get_posts( $args ); print_r($myposts); </code> No matter what arguments I pass into the $args array I don't get a... | It seems that is was a simple problem. get_posts() has various default settings, one of which is that the <code> post_status </code> is set to <code> public </code> and my custom post type which doesn't use <code> post_status </code> used the default value, <code> draft </code> . To fix this you can either query by pos... | Why Does get_posts() Return an Empty Set? | wordpress |
Here is my Code. It is get sub category from main category. and from sub category having different posts related about different products. Now issue it this that i want lowest price value from custom field that i define. so i should i do it to get lowest/min value. <code> <div> <?php $subcategories = get_categ... | Your code is badly broken in a couple of place and potentially flawed in a couple of others. <code> $price=$post->ID; $price = get_post_meta($price, 'price', true); i0 ($price <= 3500) { $minPrice=$price; </code> Line 1: Not broken but why not just use $post-> ID? Setting that to a variable named <code> $price </... | How to get lowest price from custom fields of posts | wordpress |
I've seen a couple of discussions about getting Wordpress to regenerate a unique nonce for subsequent Ajax requests, but for the life of me I can't actually get Wordpress to do it-- every time I request what I think should be a new nonce, I get the same nonce back from Wordpress. I understand the concept of WP's nonce_... | Here's a very lengthy answer of my own question that goes beyond just addressing the question of generating unique nonces for subsequent Ajax requests. This is an "add to favorites" feature that was made generic for the purposes of the answer (my feature lets users add the post IDs of photo attachments to a list of fav... | How to get a unique nonce for each Ajax request? | wordpress |
I have set up a child theme of the twentyten theme. In the themes section that under the appearance, I can only see the child theme's title, author name, and a grey box above it. How can I add an icon/image to be displayed in the grey box? | Leave a file with the name <code> screenshot.png </code> inside the root of your child theme folder and it works. The recommended image size is 600x450. The screenshot will only be shown as 300x225, but the double-sized image allows for high-resolution viewing on HiDPI displays. see on Codex | how can I add an icon/image for a child theme? | wordpress |
I have a WPMU site with hundreds of blogs on it. We are on 3.4.2 and this is the first time I'm seeing this issue within a few of my sites. Basically, what happens is that I'll create a new category and then when I click on it from the sidebar where all the categories appear, it 404's. Also, this happens when I add a n... | In the interest of closure and so someone in the future researching anything similar doesn't get sidetracked by my posting here, it turned out to be our memcached. Once we hooked up to a new cache, the category issue disappeared. | New categories are now going to 404s | wordpress |
OK I'm doing a a menu (sidebar menu) that will display this all child pages of parent page (currently open) Parent |-Child 1 |-Child 2 | Child 3 but in same time when someone is in bolded page (child) will see the same thing Parent |-Child 1 _ _|-Child 1 _ _| -Child 2 _ _|- Child 3 |-Child 2 |-Child 3 currently I use n... | Could you try this ? The idea is if there is a parent, we should list pages for the parent of this parent. <code> <?php if ( is_page() ) { if($post->post_parent) { $children = wp_list_pages('title_li=&child_of='. get_post( $post->post_parent )->post_parent .'&echo=0&sort_column=post_date&sor... | List Child Pages of Parent Parent Page (Child pages from Grand Parent) | wordpress |
I'm trying to use get_template_part to retrieve a template file based on the current post type (slug) the user is in. The template file just includes an image that is used specific to specific post types. <code> <?php get_template_part('parts/get_post_type( $post )') ?><p id="t3-splash-title"><?php $post... | There is built in support for that, kind of. While I don't see anything wrong with your code, try naming your files on the form <code> archive-mytype.php </code> , <code> content-mytype.php </code> etc. and then call <code> get_template_part </code> like this: <code> <!-- This will result in including parts/content-... | Using get_template_part to retrieve a template file based on current post type | wordpress |
I'm trying to get allow only lowercase usernames are valid usernames in my wordpress blog. I managed to write a function but it does not seem to work. <code> add_filter('validate_username' , 'simple_user', 1, 2); function simple_user($valid, $username ) { if (preg_match("/[a-z0-9]+/", $username)) { // there are spaces ... | The filter <code> validate_username </code> sends and expects a boolean value, not a string. Hook into <code> sanitize_user </code> and use <code> mb_strtolower() </code> . Sample code, not tested: <code> add_filter( 'sanitize_user', 'wpse_83689_lower_case_user_name' ); function wpse_83689_lower_case_user_name( $name )... | allow only lowercase user registrations | wordpress |
I would like to require a featured image on a site I am developing. I tried the code here: stackexchange-url ("Make featured image required") and nothing happened - the JS showed up in the site header, but I could still save the post without a featured image, and never got an error message. There are several plugins th... | Here's what I ended up doing: <code> jQuery('#post').submit(function() { if (jQuery('.force').is(':checked')) { if (jQuery("#set-post-thumbnail").find('img').size() > 0) { jQuery('#ajax-loading').hide(); jQuery('#publish').removeClass('button-primary-disabled'); return true; }else{ alert("Please set a Featured Image... | Require featured image | wordpress |
I am using "Lightbox Plus" plugin to create lightbox image overlay on the top of thumbnail galley. Now my question is how I can set a size for Thumbnails without affecting on the lightbox image overlays. I mean when I try to set a scale for Thumbnails through wp-Gallery edit option it apply the size even to the overlay... | Use <code> add_image_size() </code> : <code> add_image_size( 'custom-name', 123, 456, true ); </code> ...will create image size <code> custom-name </code> , with dimensions of 123x456px, hard-cropped. Edit Re this comment: Thanks for comment but honestly I got more confused!can you please let me know what is the 'custo... | How to Add a Custom Size for Thumbnails for WP - Gallery | wordpress |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.