question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I am doing the following to get all the children associated with a post: <code> $args = array( 'order'=&gt; 'ASC', 'post_parent' =&gt; get_the_ID(), 'post_status' =&gt; 'publish', 'post_type' =&gt; 'task' ); $tasks = get_children( $args ); </code> Now the posts of type <code> task </code> have postmeta associated with ...
This should do the trick: <code> global $wpdb; $parent = 1; // Make sure it's int (intval() it) as it's not escaped in the query $posts = $wpdb-&gt;get_results( "SELECT `post_id` AS `ID`, `meta_value` AS `Progress` FROM {$wpdb-&gt;postmeta} WHERE `meta_key`='task_progress' AND `meta_value` &lt; 100 AND `ID` IN (SELECT ...
get_children filter with postmeta
wordpress
I need to do an import of an array of checkboxes, but there is a value that I don't how it is determined. The array is based on a user meta option that I created that shows a list of category checkbox options. It grabs all of the categories and creates a checkbox option that can be saved to a user's profile. This is pa...
Use the php function unserialize() on that string and you will get a proper array. <code> $cats = get_cats_from_database(); $cats = unserialize($cats); //now $cats is an array like Array(0 =&gt; 20, 1 =&gt; 343 ); </code>
Array: What is this value based on?
wordpress
Hello guys I would like to append a link to the end of the content within my post. I currently have this in my functions.php file: <code> function ifcj_comment_link() { global $post; return ' &lt;a href="'. get_post_meta($post-&gt;ID, 'Israel In The News Audio Link', true) . '"&gt;' . __( '&lt;div id="audio-player"&gt;...
The excerpt must be used by the Theme. I don't think it is. Use 'the_content' filter to append to the post. Excerpts are usually used in feeds and only by certain themes. <code> add_filter('the_content', function($content){ if(!is_archive()) return $content; global $post; // This is the current output post ob_start(); ...
Adding a filter to my posts
wordpress
At the moment my nav menu's category list only links to normal post_type archives. I'd like to dynamically append a custom post type, specifically ?post_type=portfolio, to the end of each url that particular drop down list. But I really don't know anything about php regex at the moment, except that I think that's what ...
Here is something I came up with to solve this exact problem. <code> add_action('wp_list_categories','example_wp_list_categories'); function example_wp_list_categories($output) { global $post; foreach (get_categories() as $cat) { if (preg_match("/\/category\/$cat-&gt;slug\//", $output)) { $output = str_replace('/catego...
Dynamically append custom post type to end of url
wordpress
I found a script so I can take care that on some months I can change the number of post at a page. So I implment this script at this way : http://pastebin.com/Nbqy0KBU But still all articles are displayed as you can see here : http://test.tamarawobben.nl/2005/04 Anyone a idea why and how to solve this ? Roelof Edit 1 :...
Consider this option of achieving what you seem to be requiring: <code> function wpse31701_filter_query() { global $wp_query; // Check year and month if ( $wp_query-&gt;get( 'year' ) == 2005 and $wp_query-&gt;get( 'monthnum' ) == 5 ) // Check page number to apply offset if ( $wp_query-&gt;get( 'paged') &gt; 1 ) $wp_que...
why is this script not working on my site
wordpress
How can I get all users with atleast one post? I don't think it's possible with <code> get_users </code> function.
<code> global $wpdb; $min_posts = 5; // Make sure it's int, it's not escaped in the query $author_ids = $wpdb-&gt;get_col("SELECT `post_author` FROM (SELECT `post_author`, COUNT(*) AS `count` FROM {$wpdb-&gt;posts} WHERE `post_status`='publish' GROUP BY `post_author`) AS `stats` WHERE `count` &gt;= {$min_posts} ORDER B...
Get users with atleast one post
wordpress
I was thinking about a nicer way to display the categories in my sidebar. Instead of a plain list style, I'd like to have images / thumbnails show up as well. Currently I'm using the following: <code> &lt;?php wp_list_categories('show_last_updated=1&amp;show_count=1&amp;title_li='); ?&gt; </code> Simply displaying the ...
You can use a custom Walker , the easiest of which in your case is the <code> Walker_Category </code> and extend it like so: <code> class CategoryThumbnail_Walker extends Walker_Category { // A new element has been stumbled upon and has ended function end_el( &amp;$output, $category, $depth, $args ) { // Output the sta...
wp_list_categories: get latest featured_image of category
wordpress
I'm developing a couple of open-source plugins and a theme (all part of a "suite") that all use the same third party PHP library. I'm wondering what is the best way to include it in Wordpress. Here are some thoughts: put it in one of the plugins and require that plugin to be installed and activated create a special "co...
If each plugin/theme functions on its own, then you should probably drop the the library in every theme/plugin. Then just check to see if it a class or function from the third-party library exists before requiring it. <code> &lt;?php if( class_exists( 'SomeClass' ) ) { // require/include here } </code> or <code> &lt;?p...
Where to put third party PHP library?
wordpress
Currently the search results are all shown in the same way, no matter if it's a post or a static page. As I don't want the comment count and the categories to show up for static pages, I was wondering how to do it. The code: (Update October 22nd) <code> &lt;?php if(get_post_type() == 'page') : ?&gt; &lt;div class="rece...
<code> &lt;?php if(get_post_type() == 'page'): // Only pages ?&gt; &lt;div class="recent_postMetaSingle"&gt; &lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/eye.png" alt="Views" title="views" /&gt; &lt;?php print_page_views(get_the_ID('')); ?&gt; &lt;p&gt;This is a static page!&lt;/p&gt;&lt;/div&gt; ...
Search Results: Differentiate posts and pages
wordpress
i want to call a function using wordpress ajax and i have done a code for that also. but when i fire a ajax call it always retrun -1. i dont know what is the problem can any body help me to solve. Here is my code function.php <code> function my_AJAX_processing_function(){ //echo $getLetter = $_GET['post_id']; print_r($...
The answer is quite simple - you are not giving <code> admin-ajax </code> what it is expecting. Please refer to the source code http://core.trac.wordpress.org/browser/tags/3.2.1/wp-admin/admin-ajax.php#L17 <code> if ( ! isset( $_REQUEST['action'] ) ) die('-1'); </code> So make sure you are giving it an action (which yo...
Wordpress ajax problem need wordpress expert?
wordpress
After adding wp-custom-menu-filter plugin - to hide some menu items for not-logged in users, the current_page_item class disappeared from my menu. <code> $item-&gt;classes </code> in the walker is an empty array, instead of usual <code> page-item-$id </code> , <code> current_page_item </code> . I've looked at the sourc...
After few hours of debugging I found out, that the wps_custom_nav_menu_items() actually receives the nav_menu_items with classes, applied by the _wp_menu_item_classes_by_context, but instead of using them, it reloads the entire menu from the database! So if you change <code> $nav_items = wp_get_nav_menu_items( $menu_id...
wp-custom-menu filter removes the current_page_item class
wordpress
I added the following code to my functions.php file to create a custom post type. <code> function create_post_type() { register_post_type( 'mysite_reviews', array( 'labels' =&gt; array( 'name' =&gt; __( 'Reviews' ), 'singular_name' =&gt; __( 'Review' ) ), 'public' =&gt; true, 'menu_position' =&gt; 5, 'rewrite' =&gt; ar...
<code> flush_rewrite_rules() </code> as soon as you register the custom post type. It appears that they have not been rewritten yet, that is, most probably, why you're getting an embarrassing message. <code> register_post_type( 'mysite_reviews', array( 'labels' =&gt; array( 'name' =&gt; __( 'Reviews' ), 'singular_name'...
Why do my custom post types show up in the dashboard, but not on my site?
wordpress
The code below is part of a widget that goes with my theme. I'm trying to include a stylesheet that the widget needs by placing an add_action call to wp_head. However, the function never fires in this context. What am I missing? <code> function widget( $args, $instance ) { if(!get_option('my_slider')) return; add_actio...
There are various approaches ( including this one ), but you could consider, since you're talking about a stylesheet and not a script, simply enqueueing it from the Plugin, regardless of whether the Widget is active. (Which is worse: the few bytes of Widget-specific CSS, or the server overhead to determine if the Widge...
How to load a stylesheet into wp_head from a custom widget?
wordpress
I tried looking for info about how to exclude/remove nav menu items from custom menus, and the only stackexchange-url ("thread") I found did not have any answers that were useful to me. 1. Background: I put together a Dock menu using WP custom menus (wp_nav_menu) and jqDock on my site. Since jqDock needs continuous ima...
Method 1 You can add a constructor to your custom Walker to store some additional exclusion arguments, like: <code> class custom_nav_walker extends Walker_Nav_Menu { function __construct( $exclude = null ) { $this-&gt;exclude = $exclude; } function skip( $item ) { return in_array($item-&gt;ID, (array)$this-&gt;exclude)...
Dynamically exclude menu items from wp_nav_menu
wordpress
I'm trying to get a text-based navigation menu for the footer of my site. I'm using the <code> wp_nav_menu() </code> parameters as directed by Codex . He're a snippet of code (in <code> footer.php </code> ): <code> &lt;div id="footer"&gt; &lt;?php wp_nav_menu(array('depth'=&gt;1, 'after'=&gt;'&lt;span class="sep"&gt;|&...
The reason for your not being able to use <code> before </code> and <code> after </code> is because when you're calling <code> wp_nav_menu() </code> with a default fallback of <code> wp_page_menu() </code> , which does not have a <code> before </code> and <code> after </code> arguments. Refer to line 171: http://core.t...
Most wp_nav_menu parameters ignored
wordpress
I'm trying to implement a "publish" button from a custom post type metabox. Everything actually works fine if I either create a new button and manually call submit() or duplicate the regular submit buttons, except for one thing: if i change the title of the post, I always get the "Confirm Navigation" popup asking me if...
You can stimulate click to Update post button like this.. stackexchange-url ("Adding submit or update button to custom metabox?") <code> &lt;script&gt; jQuery('.metabox_submit').click(function(e) { e.preventDefault(); jQuery('#publish').click(); }); &lt;/script&gt; &lt;input type="submit" class="metabox_submit" value="...
Custom "Publish" / "Update" button &
wordpress
how to edit wp category widget, so it would not show one of specified category? For example, it shows all categories in list, and I need to remove category Books, from it, how can I do it? Best regards, Y2ok
<code> // This alters the get get_terms() arguments and hides some categories function widget_category_excluder($args){ // Replace the numbers with category IDs you need hidden $args['exclude'] = $args['exclude'].',1,2,3,'; // Keep it safe! // Or use exclude_tree to exclude children categories also // $args['exclude'] ...
how to edit wp category widget
wordpress
I created a checkbox option for the user_meta (user profile). They are checkboxes assigning users to categories. The problem is that I need to do a mass update for all of my users 1500+ and going through them individually would take too long. I need to choose the intended categories for each user. There are 180 categor...
<code> update_user_meta() </code> is what should assist you in doing this. Feed what <code> get_users() </code> returns and update the meta data for each and every one of them with the required values. Assuming that you are going to store a serialized array, your custom query will have to unserialize each result in ord...
Mass Update User Profile Checkbox Options
wordpress
I know that Wordpress allows us to create a new user and the user's avatar is got from Gravatar service base on their email. How can I add authors in WordPress and assign them a picture (without using Gravatar service ) ? Thank you ! P/S: I am sorry for my bad English. :)
there are a bunch of plugins that adds this functionality to wordpress, this one seems pretty neat, User Avatar
How can I add authors in WordPress and assign them a picture?
wordpress
I was wondering is there a way to create a post for every user. Sort of like a mass update that would associate certain user meta to the post created. I would prefer running a loop script that goes through all users and creates a post for each using certain user meta info. For instance, if I have five users that I woul...
Create this as a plugin and activate it. It deactivates itself after it creates a primary page for Authors and sub-pages for each Author+ or better Role. At the end, it deactivates itself. Improve it as you wish. It uses <code> // Hook activation to create new Author Pages register_activation_hook(__FILE__, function(){...
Create post for every user?
wordpress
how i can remove indent from comments reply if someone reply comments it indent to previous reply and keep adding indent..how i can make it just indent first reply and other show under this.. i searched for solution on google and stackexchange but could't find any..its output simple ordered list for comments and reply ...
If you want to get rid of threading completely you can control it in <code> Settings </code> > <code> Discussion </code> > <code> Other comment settings </code> > <code> Enable threaded (nested) comments </code> . If you want to keep functionality and markup, but change it visually you would need to do that via CSS, wh...
how to remove indent from twently eleven comments reply
wordpress
I want to run a function that looks at the current url params of the page that is requested and sets a cookie based on those params. So, I guess I'm looking for: The Wordpress Hook that allows me to do this before the page is even loaded A way to get the requested URL
<code> // Kick in right before theme takes over, when WP is all loaded add_action('wp', function(){ list($uri, $qs) = explode('?', $_SERVER['REQUEST_URI']); // Do stuff here: // ... STUFF ... }); </code> Cheers!
Hook for page Request?
wordpress
So I'm developing a theme where essentially all content will be displayed on a single page (index). Well, the content isn't exactly conventional. In other words, it's not just a title and body, maybe a few custom post fields. It's very different from section to section. What I was thinking of doing was just creating al...
Option values are <code> longtext </code> . So you can store up to 4,294,967,295 or 4GB (232 – 1) bytes in an option value. I wouldn’t do that … but feel free to test the edge cases. :)
Single Page Design, Storing in Theme Options
wordpress
why my sql statement is not returning any value.. is this wrong? <code> &lt;?php global $wpdb; $result = $wpdb-&gt;get_results($wpdb-&gt;prepare("SELECT * FROM $wpdb-&gt;wp_frm_item_metas")); foreach ($result as $item){ $eventname= $result-&gt;meta_value; } ?&gt; &lt;h2&gt;&lt;?php echo $eventname;?&gt;&lt;/h2&gt; </co...
I believe for your foreach function should be like below: <code> foreach ($result as $item){ $eventname= $item-&gt;meta_value; } </code>
Retrieving a Value from a wp-database
wordpress
We've imported a blog from one domain to another and the permalink thats been created for category archives is: domain.com/category/graphic-design-blog/tips-for-artist/ where category/graphic-design-blog/ is superflous. The permalink structure is set to the default (2011/10/post-name) and this is working fine for singl...
Sorry [no-one ;)], I figured it out: /category/ can be removed in Yoast SEO by checking ' Strip the category base from the category URL. ' The other part 'graphic-design-blog' was displayed because all of the categories were had the parent 'blog' which had the slug 'graphic-design-blog'. I set all the sub-categories to...
How to shorten the Permalink after WP> WP blog import?
wordpress
I'm trying to save my client a few clicks. I've created a custom role of "Customer" and I'd like to get them to that screen, without having to have them click "Users" and then select the "Customer" role. So, I have a custom menu called "Orders". I'd like to add a submenu called "Customers" and "load" this page: users.p...
You can add an interal link quite easily, it's the same approach you use for adding custom items, you simply exclude a callback function and set the menu slug to the applicable URL, here's an example. <code> add_action( 'admin_menu', 'add_user_type_link' ); function add_user_type_link() { add_submenu_page( 'users.php',...
Admin - Load existing admin template as a submenu page
wordpress
how do I get names of child categories of an arbitrary Post? For example i got category slug - 'motorbikes' and I got subcategories for it. So I need to get each posts subcategory name thats inside category with slug motorbikes. Y2ok
To get the child categories of a given parent category slug, use a combination of <code> get_category_by_slug() </code> and <code> get_categories() </code> . The latter function will return an array of category objects matching the specified query arguments array; the former will return the ID of a category, given its ...
How to get child categories of a given Post
wordpress
The problem After typing my post/page in the visual editor, when I switch to the HTML editor, the expected HTML elements do not show. Headings appear but paragraphs and divs do not. A minority of people have suggested that only one editor can be used. My question Can I not interchange between the visual and HTML tabs w...
You can switch back and forth between the editors as much as you want. But the <code> &lt;p&gt;&lt;/p&gt; </code> tags usually don't show up in the HTML edit view unless there's special styling applied to the paragraph (i.e. font size, color, alignment). Let's say you have the following in the HTML editor : <code> Lore...
WordPress HTML editor panel is not showing HTML elements
wordpress
I'm using a plugin called Recent category post widget. Unfortunately the plugin developer is no longer offering support. The way this plugin is coded, displays only one instance of the widget (meaning that I can use this widget only once). What must be changed in the code below so as to use multiple instances of the wi...
You need to recode your plugin to make use of the Wordpress Widget API
How to display more than one instance for a widget?
wordpress
I'm currently using the menu_order field in the DB to have some custom ordering of posts. I want to expose this field to the user via the admin section, like it is when editing a Page (in Page Attributes). Is there a simple way to do this?
<code> &lt;?php add_action( 'init', 'wpse31629_init' ); function wpse31629_init() { add_post_type_support( 'post', 'page-attributes' ); } </code> Add that to your <code> functions.php </code> or in a plugin file and you'll get an attributes dialog box with the menu order input.
How can I add a box to edit Order on a regular post?
wordpress
Trying to replicate some functionality I've seen on a few other themes before, but would like to know/understand for my own uses. I've created a custom post type, called "testimonials". I believe I've knocked out a pretty good chunk of the setup, using Justin Tadlock's awesome post on Custom Post Types . I've also seen...
There is a filter <code> get_sample_permalink_html </code> that returns this area as a string. Here's how you can use it: <code> &lt;?php add_filter('get_sample_permalink_html', 'perm', '',4); function perm($return, $id, $new_title, $new_slug){ global $post; if($post-&gt;post_type == 'testimonials') { $ret2 = preg_repl...
Removing Edit Permalink/View "Custom Post Type" areas
wordpress
I installed a theme called "The Dawn". It supports the addition of new type of post and a taxonomy. Here's the code: <code> register_post_type('portfolio', array( 'description' =&gt; 'TheDawn Portfolio', 'show_ui' =&gt; true, 'menu_position' =&gt; 5, 'menu_icon' =&gt; get_bloginfo('template_directory') . '/images/admin...
Try going to your settings--> permalinks and hitting "Save" . WordPress is not aware of the code change you made until it refreshes the permalinks. Adding this^ so you can close this Question.
register_post_type and register taxonomy and htaccess
wordpress
I'm trying to edit a wordpress theme. The following is the section of code where the list of categories is retrieved and displayed in a drop-down menu. <code> &lt;p&gt; &lt;label for="entrycat"&gt;* &lt;?php _e( "Question category:", "sofa_qanda" ); ?&gt;&lt;/label&gt; &lt;?php $select = wp_dropdown_categories( 'show_o...
http://codex.wordpress.org/Function_Reference/wp_dropdown_categories use the 'exclude' parameter; example: <code> $select = wp_dropdown_categories( 'show_option_none=Select&amp;show_count=0&amp;orderby=name&amp;echo=0&amp;hide_empty=0&amp;exclude=10' ); </code>
How to exclude a particular category from the category list
wordpress
For my related posts I have set up a scrollable container. I need the HTML to be outside of the loop or otherwise the layout will be a mess if there are no related posts to display (missing divs that are inside the loop only if there are related posts to be shown). So, the only option I have is to display a message wit...
I still can't see how the code and the problem is substantially different from your original topic; however, try to add your text into the typical 'else' location for a loop if no posts are found; change this line: <code> &lt;?php endwhile; endif; ?&gt; </code> to: <code> &lt;?php endwhile; else : echo '&lt;h3 class="n...
Implement "No related posts for this entry" into the loop?
wordpress
I need to be able to tell if an admin is logged in ouside of the loop. This is needed for some php files that are part of a WP site but do not use <code> require( '../wp-load.php ); </code> What I need to do is keep the Google Analytics tracker JS from firing for logged in admins, but track everyone else. How do I find...
You can use current_user_can() to determine if an admin user is logged and load your Google tracking code using wp_enqueue_script with an if statement in functions.php <code> if ( ! current_user_can( 'edit_posts' ) ) { wp_enqueue_script( 'google-tracking'); } </code>
How to determine if an admin is logged in outside the loop
wordpress
I am building a form where a user can submit an article from the front end.. So far so good... To this form i am doing some submission check using javascript.. When i get to check if a category is choosen This is the line the retrives categories in the form: <code> &lt;?php wp_dropdown_categories('show_option_none=----...
Ok... as thing go when your trying to solve somethimg you have no peace until its fixed so.. i went ahead and did some clear mind thinking (after a night sleep) and got that i can check the HTML for the values returen. Just wanted to share incase anyone stumbles with the need for this info This: <code> &lt;?php wp_drop...
Form Value of drop down category + Translation of 'show option none'
wordpress
Hi I'm learning theming options based on the existing theme TwentyEleven. I've come across the following code in inc/theme-options.php <code> return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options ); </code> I can't seem to find the add_filter for 'twentyeleven_default_theme_options', or doe...
I don't believe there is an <code> add_filter() </code> call anywhere. If you want to override the option defaults, you can call your own <code> add_filter() </code> to do so, either in a Plugin or in a Child Theme. EDIT An <code> apply_filters() </code> call is nothing more than a filter hook definition : basically, i...
Location of twentyeleven theme's option filters?
wordpress
I have a page called "About Us" with some static content. I want to display that static content on the home page. Would I need to do a custom query that returns the about page, or is there a better way? <code> $about_page = new WP_Query('p=7'); // is this basically it? </code> Is there a better way to do this? A more d...
If you're using WP_Query, then assign that page a custom meta key 'home_content' with a value as 1. Then use WP_Query's custom field parameters to loop over it. If you can restrict the title as 'About' everywhere, use get_page_by_title , and if you can restrict the slug as 'about', use get_page_by_path . These methods ...
Display content from "About Us" page on the Home Page
wordpress
I know how to write querry args for WP_Query if it's a single key : for example, if query posts with the metakey of 'type'-- <code> $query_args['type'] = (array)$type; </code> Now, the problem is-- the item I want to querry is saved inside an array, this array is saved as a postmeta. This is my array: <code> $details =...
Jenny, first of all, I think you may be better off using Taxonomy Parameters in you queries. However, there are a couple of hackish ways to do what you want to some extent. <code> $my_query = new WP_Query( 'post_type=post&amp;posts_per_page=-1' ); $posts = $my_query-&gt;get_posts(); foreach ( $posts as &amp;$post ) { /...
How to querry for an item that saved in an array?
wordpress
So, According to the WordPress theme download page; the theme 'Twenty Ten' and it's child theme/plugin 'Responsive Twenty Ten' are compatible with 2.8+ I'm stuck with using 2.8.5 at work, I don't have an answer to why - but am. I've uploaded both the plugin and the base theme manually - and was stoked to begin implemen...
home_url() function is implemented in Wordpress since version 3.0.0, and you are using version 2.8.5. To fix this error edit <code> wp-content/themes/twentyten 3/header.php </code> file - replace: <code> home_url(); </code> with: <code> 'http://'.$_SERVER["SERVER_NAME"] </code> This is hotfix, and i'm afraid you will r...
WordPress 2.8.5 & 'Responsive Twenty Ten' - error
wordpress
I have a custom post type called portfolio. I need a previous/next link WITHOUT a plugin. Anybody have a solution? Example post: http://themeforward.com/demo2/archives/portfolio/boat <code> &lt;?php get_header(); ?&gt; &lt;!-- Begin wrap --&gt; &lt;div class="clear"&gt; &lt;div id="full_container"&gt; &lt;div id="conte...
If you need next/previous links for single posts, there is the built in <code> next_post_link </code> function and matching <code> previous_post_link </code> , both of which should probably be used within the loop. For archives, use <code> next_posts_link </code> and <code> previous_posts_link </code> . All of these wi...
Custom Post Type Next/Previous Link?
wordpress
I've created a site with nine (gulp) custom post types. It's a huge site unsurprisingly. The 9 post types fit on the admin menu but I was wondering if there is a limit to the number of extra post types you are allowed in WordPress? Say this because when enabling PollDaddy that adds two more tabs (Polls and Ratings) whi...
The problem is probably due to clashes in the <code> menu_position </code> argument when registering a post type. Try editing those to values between the standard multiples of 10 and see if it solves the problem.
Custom Post Type / Tab Limit
wordpress
Does anybody know of a plugin available for WordPress that would require a new user to enter their mobile phone number as part of the sign up process? The user would then be sent a verification code via SMS which they would have to enter to complete the sign up process. Any ideas? Thanks
Consider these resources: http://www.marketingtechblog.com/wordpress/wordpress-sms-mobile-alert-subscriptio/ http://www.bulksms.com/int/docs/eapi/third_party_api/ http://www.twilio.com/docs/libraries/ The concept behind this would be to send a randomly generated string to the mobile phone number that the user enters, s...
Verify signup via SMS?
wordpress
I have Boldy theme on a 3.2.1 instance of Wordpress. I have installed the plugin WP-PostRatings . I want it to show up on my individual posts when posts are viewed individually on a page. I installed and activated the plugin. I added <code> if(function_exists('the_ratings')) { the_ratings(); } ?&gt; </code> within my s...
few things you can check the code is within the loop the plugin is activated check plugin option page and select a rating type check page source code and see what is being generated. if all ok. your css is not blocking any rating star tag. de-activate, uninstall, delete and re-install the plugin
WP-PostRatings - how to make rating show up?
wordpress
I see that there are a lot of similar questions here at WPSE, and I've tried many of the suggestions mentioned trying to solve my problem but with no success. I have a category called News. In this category I want to run a custom query using WP Query to fetch and display articles, spread out through multiple pages usin...
This could be a plugin compatibility problem. Have you tried to disable all plugins and see if that solves the problem? I found this which may also be of help: http://dre.im/if-pages-return-a-404-after-wordpress-3-1-upgrade/ Log in to wp-admin and go to permalinks, click save (this should refresh your permalinks). Chec...
WP-PageNavi gives me a 404 when using WP Query
wordpress
Well, my blog is a bit Image Heavy to say the least. I've been using different types of minification plugins, but they all seem to break my site. When I tell the plugins to compress and join my css &amp; javascript files... it completely gets rid of them and my site becomes nothing but an unorganized mess of text and p...
This is normal, minification of CSS/HTML and JS is not a magic button. If you have no plugins and 1 style-sheet and minimal javascript (aka not more than 1 function) it will work, but anything above that and your looking at conflict and load order problems. To properly minify takes work, you have to either do it manual...
Minification Plugins break my website
wordpress
What function changes a post's timestamp? I created a post from frontend script, but I need to add a date picker to set the date of the visit.
You should be able to submit the following information to set a custom date <code> $_POST['aa'] // Month $_POST['mm'] // Day $_POST['jj'] // Year $_POST['hh'] // Hour $_POST['mn'] // Minute $_POST['ss'] // Second </code>
What function changes a post's timestamp?
wordpress
I have installed the Contact Form 7 plugin on my WP 3.2.1 instance. I have setup a contact form for users to request evaluations. This is all working fine, but I was hoping that when they submitted a request, I could ping them an email with an attached product brochure. I have it currently setup like this: I have tried...
Here's how to do it: http://wordpress.org/support/topic/contact-form-7-sending-attachments-without-user-upload
Contact Form 7 - Send attachment to submitter?
wordpress
I was looking for a plugin that will enable me to hide an image on the excerpt, but show it on the single post view. Anyone knows if there is any?
According to the wordpress documentation this is how it is supposed to work out of the box. Maybe I misunderstood the question, but by default the excerpt should strip html tags and graphics.
Plugin to hide image in excerpt
wordpress
Should I register both parent and child as <code> 'hierarchical' =&gt; true </code> , if there's no grandchild? If "Movie" is the top level taxonomy, when I register a child, is it as simply as: <code> 'parent_item' =&gt; __( 'Parent Movie' ) </code> ? How to automatically asign a child taxonomy to a post? So far, I fi...
Too much for a comment, so I'll leave it for an answer: You're asking a lot of Qs that should actually be different Qs and not dumped into a single one. (Ad 1.) You don't register "child" or "parent" taxonomies. You add (child-)terms to a hierarchical taxonomy via the WP Back-End UI. You can do it programmatically with...
How to register child taxonomies?
wordpress
Is it possible to hook 3 different functions to the same filter conditionally, like: <code> &lt;?php if(a){ add_filter('the_content', 'fnc_1'); } else if(b){ add_filter('the_content', 'fnc_2'); } else{ add_filter('the_content', 'fnc_3'); } ?&gt; </code> Or if this isn't possible, then can I pass an additional argument ...
Since it does appear to be an interesting question, I'll go ahead an compile an answer. Method 1 Totally fine, will work. Here's the compact piece of code I used to test it: <code> function fnc_1( $content ) { return 'func1 :: '.$content; } function fnc_2( $content ) { return 'func2 :: '.$content; } function fnc_3( $co...
Hook different functions to the same filter conditionally OR Pass additional arguments to existing filter?
wordpress
How to create new role with same capabilities of existing role. Eg: I would like to create a new role with same capabilities of administrator or editor and so on..
Try this... This should work. <code> &lt;?php add_action('init', 'cloneRole'); function cloneRole() { global $wp_roles; if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $adm = $wp_roles-&gt;get_role('administrator'); //Adding a 'new_role' with all admin caps $wp_roles-&gt;add_role('new_role', 'My Custom Role', $...
How to create a clone role in wordpress
wordpress
Trying to set a 'removed' date time in a plugin query but I'm not sure how to use UPDATE SET with $wpdb-> prepare. Here's my query: <code> $cur_date = date('Y-m-d G:i:s'); $rows_affected = $wpdb-&gt;query( $wpdb-&gt;prepare(" UPDATE $table SET ( removed, post_id, user_id, status ) VALUES ( %s, %d, %d, %d ) "), array( $...
I sort of fixed your query. It needs a table and a WHERE condition to prevent changing all rows. Even a LIMIT 1 at the end won't hurt. <code> $rows_affected = $wpdb-&gt;query( $wpdb-&gt;prepare( "UPDATE {$table} SET removed = %s, post_id = %d, user_id = %d, status = %d;", $cur_date = date('Y-m-d H:i:s'), $postid, $user...
wpdb-> prepare and mysql UPDATE - how is it done?
wordpress
I'm trying to display different images in a page that links to categories. Currently i have a page that shows the categories and the pages for the categories but it needs a slight change. I need to display the category name with an image for that category and a background for it. I've attached an image to explain what ...
I would suggest looking at a plugin like images for categories and seeing if you can extend it to allow 2 images per category.
Image menu showing categories in page
wordpress
I am trying to store simple data, a few links inside wp_options. Basically using the following way: <code> update_option( 'simple_links', '&lt;a href=""&gt;link 1&lt;/a&gt;' ); </code> my question is if it is allowed, I dont want to create new table for it, just a few links permanently stored inside the footer. Is that...
To recap the comment chain above: I think that's a perfectly valid way of storing some options in the database, however, it's good practice to prepend your option name with some unique characters pertaining to your site or something, like <code> 'my_simple_links' </code> to avoid possible collisions with other plugins ...
store simple data in get_option()
wordpress
I'm setting up a way to feed the title of a WP post as the title argument for a reddit button . It works fine unless there is an encoded character in the string: <code> apostrophe&amp;#8217;s break things. </code> ...Which results in reddit double encoding the ampersand: <code> apostrophe&amp;amp;#8217;s break things. ...
Try this: <code> $title = get_post_field('post_title', $post_id, 'raw'); </code> However I'd get to the bottom of what encoding reddit code would prefer. Echoing raw stuff is poor idea for security.
Outputting post title without encoding
wordpress
I essentially want password protected/private pages/posts in WP to work as they currently do, but completely disregard the functionality for certain IP addresses. I've looked into filters/actions and don't see anything that seems promising, again I would prefer to do this without creating a specific category or anythin...
Bypass Password Protected Posts You are, unfortunately right about the lack of filters, and hacking the core is inevitable. One solutions that seems to work revolves around the <code> sanitize_post_field() </code> function which fires off a number of interesting filters if its <code> $context </code> argument is not se...
Excluding private/protected posts via IP
wordpress
I've no idea why i can't add a Page with Name <code> 2011 </code> . Wordpress changes the URL Slug to 2011-01. There is no Post with this Name in my Database. I tried zu flush my rewrite rules but nothing seems to be work. If i add a Page 2013 it works fine. But only once... If i delete this Page (from Trash) i can't a...
This has to do with how paging-within-a-page works. See ticket #5305 . There's a plugin that will allow you to have numeric slugs if you're willing to sacrifice paging: http://wordpress.org/extend/plugins/allow-numeric-stubs/
Can't add a Page with Name 2011
wordpress
I'm using a class to retrieve values from custom tables that I need to use in different files of my WordPress Theme and im not sure which is the best approach for this. This is the class i got right now (dont blame as im a bit noob :D) <code> class Plans { public $free_plans; public $purchased_plans; private $free_coun...
The easiest way to have access to your variable in other files is to do exactly what Chip suggested, globalize the variable. This is the same thing WordPress does to make global variables like <code> $wpdb </code> available in other files. I can already see you're making calls to the global <code> $wpdb </code> variabl...
Im using a right approach to use this class inside WordPress theme?
wordpress
I'm writing a WP Theme where registered users can email post authors sending them en email from the post's page itself. So I created a contact form in which I get the user and author infos and emails and I put them in hidden input fields to pass them to the php mail function. Does WordPress have a way to obfuscate the ...
Core function to obfuscate mail addresses: <code> antispambot( $emailaddy, $mailto ); </code> Second arg is 0 or 1 and optional.
Obfuscating Email Addresses in Form Fields
wordpress
I am currently looking at creating a new type of site archive within WordPress that allows users to filter by category AND by year rather than the default category OR year. I am hoping to build a sidebar widget that creates the interface but I am looking for ideas and advice on creating the custom permalink setup. Idea...
Following the suggestions of @StephenHarris I have developed the code a little further and come up with the following: <code> add_action('generate_rewrite_rules', 'my_rewrite_rules'); function my_rewrite_rules( $wp_rewrite ) { // handles paged/pagination requests $new_rules = array('news/(.+)/year/(.+)/page/?([2-9][0-9...
Category archive by year with permalink support /category/YYYY
wordpress
I am using this function to get imnages urls from google <code> function getGoogleImg($k) { $url = "http://images.google.com/images?as_q=##query##&amp;hl=it&amp;imgtbs=z&amp;btnG=Cerca+con+Google&amp;as_epq=&amp;as_oq=&amp;as_eq=&amp;imgtype=&amp;imgsz=m&amp;imgw=&amp;imgh=&amp;imgar=&amp;as_filetype=&amp;imgc=&amp;as_...
If you look at your current setup, you can see that your <code> add_image_to_save_post </code> function is fired off when <code> wp_insert_post </code> is performed. <code> wp_insert_post </code> is fired off when a post is inserted into the database, and as you may know, as soon as you click "Add New" in WordPress a d...
I want to add post meta for picture thum during submit for revision
wordpress
I have a problem with output text. When I editing text in the WordPress control panel everything looks normal: http://i.stack.imgur.com/GaIut.png but when I output it to the html: <code> &lt;?php esc_html( wp_richedit_pre( $_product-&gt;details ) ); ?&gt; </code> It looks like this: http://i.stack.imgur.com/r81xE.png W...
hmm ... strange. I looked to the file ' wp-includes/formatting.php ' on the functions *wp_richedit_pre*: <code> function wp_richedit_pre($text) { // Filtering a blank results in an annoying &lt;br /&gt;\n if ( empty($text) ) return apply_filters('richedit_pre', ''); $output = convert_chars($text); $output = wpautop($ou...
Problem with WordPress output text ('esc_html' & 'wp_richedit_pre')
wordpress
I'm trying to build an author list that would show all authors that have written a Custom Post Type post, and hide authors that have no posts. With <code> wp_list_authors </code> it would be easy to show users that have written Posts (not CPT). This does not show the users that have published Custom Post Types, it affe...
<code> wp_list_authors() </code> , internally gets posts that are only of type <code> post </code> . See line 294 http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/author-template.php#L273 As you have noted, stackexchange-url ("this") answer is great and with some modification can do what you want. <code> f...
How to list users that have written custom post types and hide the ones that have not?
wordpress
I'm using the "Featured Image" meta box which allows you to attach a secondary thumbail to a post. The title for this box is defined in the Wordpress codebase like so: <code> __('Featured Image') </code> Which looks to be a wrapper for the translate methods. I'm wondering how to change this text without having to do an...
Sure, the <code> gettext </code> filter does exactly what you require. Here's some code that should work out of the box: <code> function wpse31449_translate_my_stuff($translation, $text, $domain) { if ($text == 'Featured Image') return 'Post Image'; return $translation; } add_filter( 'gettext', 'wpse31449_translate_my_...
Easy way to update a single translation entry without having to translate
wordpress
Another one of these paging errors you see here so often. I searched high and low for a fix but have come up with nada so far. I am paging CPT results using my archive-{$post_type}.php template and getting an incomplete return of posts. I have set posts_per_page to 8, and am return 3 pages to get 24 results. There are ...
I think <code> next_posts_link() </code> is using the global <code> $wp_query </code> to determine pagination, but you've created a new query here. Try passing <code> max_num_pages </code> from your <code> $loop </code> query to it: <code> next_posts_link( '&lt;span class="nextpost"&gt;Next&lt;/span&gt;', $loop-&gt;max...
Custom post type pagination error
wordpress
I am currently using this code: <code> function change_author_permalinks() { global $wp_rewrite; $wp_rewrite-&gt;author_base = 'connect/member'; } add_action('init','change_author_permalinks'); </code> but my current <code> front </code> set on my blog is: <code> share </code> So the above generates a URL like so: <cod...
This is the best solution I have come up with but I welcome better ways: <code> function change_author_permalinks() { global $wp_rewrite; $wp_rewrite-&gt;author_base = 'connect/member'; $wp_rewrite-&gt;author_structure = "/" . $wp_rewrite-&gt;author_base . '/%author%'; add_rewrite_rule('connect/member/([^/]+)/?$', 'ind...
How to change author base without front
wordpress
I'm trying to get the terms of a taxonomy (kind) and the number of content they have but only for a specific category (get_parent_page_slug() = city name = category slug). This is what I have so far: <code> $args = array( // 'taxonomy' =&gt; 'tipo', 'hide_empty' =&gt; 1, ); $terms = get_terms('kind', $args); //var_dump...
Well, I do not know if this is quite OK, but is returning the expected results ... so at the moment this it is enough for me. <code> function my_custom_get_terms( $my_tax, $my_category, $show_all = true ){ global $wpdb; global $pagename; $query = "SELECT Count(wp_posts.ID) AS my_term_count, wp_term_taxonomy.term_taxono...
Using get_terms() to list terms from one custom taxonomy AND from one specific built-in category
wordpress
I have a theme that does not work in IE so I would like to be able to detect the browser and redirect to a "sorry this doesn't work for your browser" type or what ever solution you guys can suggest for this. Any ideas on the best way to go about this?
Try using this code to check if it's IE ( original source )... <code> &lt;?php if (isset($_SERVER['HTTP_USER_AGENT']) &amp;&amp; (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) return true; else return false; ?&gt; </code> You'll have to hook it up with an action and redirect accordingly.
How to detect and display a page only for IE?
wordpress
I have a really annoying problem. If there are no comments, comments won't show up. If there are no pingbacks, won't show up. However, if there are pingbacks and I have a lot of comments, so there's a page 2, page 3 etc. of comments, then the following happens: The pingbacks show up properly on page 1 . If I go to page...
Since you're listing pings separately from comments, you probably need to filter <code> get_comments_number </code> to exclude pings. Here's how I do it : <code> &lt;?php function oenology_comment_count( $count ) { // Only filter the comments number // in the front-end display if ( // WordPress conditional that returns...
Comments vs. Pingbacks next page issue
wordpress
My new WordPress [blog]: http://wuyajun.info/ keeps refreshing in Chrome browser, gets loading error in Firefox, but works normal in IE. Plugins installed that may cause the problem: Facebook AWD All in One. Hope someone can help me on this, thank you. Nathan Nov 15, 2011 update Just to clarify the refreshing problem w...
As mentioned, clear your cache. I have no problem with Firefox 7.01 or Iron (Chromium ) on Windows. I would also deactivate all plugins and see if that fixes it. If so then activate them one by one and see if you can find which one causes the problem. What happens if you use another theme? Do you have another computer ...
My new WordPress blog keeps refreshing in Chrome browser
wordpress
I'm running WordPress 3.2.1 on a CentOS box and I'm getting reports from my writers saying they get HTTP 500 errors when they try to update an exciting post. I've tried the same and have similar problems (although the HTTP 500 only shows in Chrome, Safari and Firefox simply give me a blank window). I've increased my lo...
If the problem is easily reproducible (i.e. you can make it happen again and again by following a set of steps), do this: Step 1: Document the steps required to cause the problem. Step 2: Document all of the plugins you have running Step 3: Deactivate all of your plugins! Step 4: Perform the steps outlined in step 1 St...
Random HTTP 500 error in WordPress
wordpress
<code> &lt;?php query_posts( array( 'showposts' =&gt; -1, 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'page', 'orderby' =&gt; 'title', 'order' =&gt; 'ASC', 'meta_key' =&gt; 'featured_product', 'meta_value' =&gt; 1 ) ); ?&gt; </code> For featured products. <code> &lt;?php query_posts( array( 'showposts' =&gt; -1...
The best solution i found for querying posts where the meta_key <code> IS NOT </code> or doesn't exists is to use the <code> posts_where </code> filter with a small sub-query, try this: <code> //paste this function in your theme's functions.php function metakey_no_featured( $where ) { global $wp_query; global $wpdb; $w...
query posts with custom field meta value
wordpress
I have inherited a WP 3.2.1 site which uses prettyPhoto to load content via ajax. This was working before I enabled permalinks on the site. The Custom Post Type UI plugin is installed. I can browse to my custom post type at mysite.com/story/name-of-story but loading via ajax results in a 404. The links which trigger th...
All ajax requests should be routed through the handy <code> /wp-admin/admin-ajax.php </code> file. It works with the great WP hooks system. So you send an "action" with your request and use that as part of the action into which you hook your function. So, let's say your ajax call looks like this (with jQuery) <code> jQ...
Post will not load via ajax
wordpress
I want to create RSS feed for categories in WordPress.Is this possible? How could I do it? Thanks
Category feeds are a part of WordPress core. e.g. for category <code> foobar </code> , the RSS feed link is: <code> www.example.com/category/foobar/feed </code> Easy-peasy!
How to Create RSS Feeds for categories in Wordpress?
wordpress
I have a menu. It has two items: the first is a link ("Index", www.domain.com) the second one is a link to a category page I have the requirement to remove the first link when I'm on the index page and remove the second link when I'm on that category. Ideas?
The code that this menu produces is this: <code> &lt;ul id="dd" class="dd"&gt; &lt;li id="menu-item-142" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-142"&gt; &lt;a href="http://www.domain.com"&gt;Index&lt;/a&gt; &lt;/li&gt; &lt;li id="menu-item-102" class="menu-item menu-item...
Remove the current item from a menu
wordpress
I have a comment form that has <code> name </code> , <code> email </code> , <code> brief </code> , <code> detailed </code> and <code> rating </code> fields. The <code> name </code> , <code> email </code> , <code> brief </code> and <code> rating </code> need to be required, but the latter two are custom fields and I can...
Here is a stackexchange-url ("related question") that should answer yours. Basicly you want to use the <code> pre_comment_on_post </code> hook <code> function custom_validate_comment() { //validate for brief and rating if( empty( $_POST['brief']) || empty( $_POST['rating']) ) wp_die( __('Error: you must fill in both th...
How to make custom comment fields required and message field not required
wordpress
I'm trying to add post to custom terms within a custom taxonomy. Not sure if I'm tackling this right. So far we have the custom taxomony 'warehouse', and the custom term 'Old Stock'. Problem is that when I try to add the term to the post using the term_id then it creates a new term with the id as a name. Here is the co...
When dealing with this, it turned out that the $parent var had to be casted as an int. Looking at the function wp_set_object_terms, it tests the param $parent with is_int(). The var $parent was coming from $_POST which was sent though http post using ajax. Somewhere along the way, probably on the javascript side, my in...
Set post terms by term id
wordpress
I have to get some custom post types and need to do that with WP_Query (query_posts doesn't work). How can I do the pagination? Whatever I tried didn't work... any help would be awesome I can't crack this alone... <code> $args = array( 'tax_query' =&gt; array( 'posts_per_page' =&gt; 5, array( 'author' =&gt; $user_id, '...
If you could tell us what you're exactly trying to achieve, we can help you better! <code> &lt;?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; $args = array( 'post_type' =&gt; 'question', 'posts_per_page' =&gt; -1, 'paged' =&gt; $paged, 'author' =&gt; $user_id ); $my_query = new WP_Query($args); if($...
WP_query and pagination?
wordpress
Unfortunately buddypress breaks a facebook connect script because of the rewrite rules. It changes <code> /wp-login.php?action=register </code> into <code> /register/ </code> I tried to find where the custom rewrite rule is located but wasn't successful. Is there any way to just add something to .htaccess that wp leave...
I'm assuming that you're working with one of the latest versions, but I used the latest 1.5.1. Without knowing how your specific Facebook Connect plugin works and why it breaks here's what I've come up with. Short answer <code> // bp-members/bp-members-signup.php ~ line 611 if ( defined( 'BP_SKIP_REGISTRATION_REDIRECT'...
Rewrite rule that wp-login.php?action=register is left alone
wordpress
I made a custom post type called Product. And a taxonomy with the name 'product-category'. These taxonomies have pages where we show a list of the products that have that taxonomy. Now my question is how to get all the taxonomies as a menu in the header. Its an awful lot of work to add it manually in the menu editor. A...
You can use wp_list_categories() which by default, generates nested unordered lists (ul) and just pass <code> product-category </code> as the taxonomy parameter for example: <code> add_filter('wp_nav_menu_items','add_custom categories', 10, 2); function add_custom categories($items, $args) { $items .= '&lt;li&gt;' . wp...
How to output all taxonomy links from a custom post type in a menu?
wordpress
I have been searching high and low for a way to count the amount of results from a get_users query. Most of what I found is to count the total number of posts in a post query, but nothing for counting the total number of users in the get_users query. Can someone point it out for me? Thanks a lot.
when you use <code> get_users() </code> it retrieves an array of users matching the criteria given in <code> $args </code> which means you can simply use PHP's <code> count() </code> function e.g: <code> $users = get_users($args); $number_of_users = count($users); </code>
How to count get_users query?
wordpress
Sometimes it's necessary to figure out CSS errors or whatever and then it's great if you have a minimal test page where you just insert the specific code you want to test. How can I create such an empty test.php? All I could find was this . However, doing so will only create a page that will have the same styling as th...
I usually do this for just code (no HTML): <code> add_action('template_redirect', 'test'); function test() { // code goes here die; } </code> For dealing with HTML I prefer blank theme, set up for testing. If you want to test in context of existing theme create custom page template , add/remove elements according to yo...
Create a blank test.php
wordpress
On the single post page I want to link the avatar function to the author profile, but I tried <code> &lt;a href="&lt;?php the_author_posts_link(); ?&gt;"&gt; &lt;img src="&lt;?php echo get_avatar($post-&gt;post_author, '64', $avatar); ?&gt;"&gt; &lt;/a&gt; </code> but that doesn't work. Also, how can I display the nick...
This a short compilation of the multiple comments above, so that future visitors don't have to read each and every one of them. First of all, <code> the_author_posts_link() </code> is a deprecated function since version 2.1, so <code> get_author_posts_url() </code> or <code> the_author_posts_url() </code> should be use...
How to link avatar and nickname to profile
wordpress
I've set up a custom walker, and it works as desired when I hard code my variable. What I want is to be able to call my walker and pass it a variable that is used in the walker. For example: <code> 'walker' =&gt; new Plus_walker($refine =&gt; 'review'), </code> The walker I've tweaked to output http://URL/review in ord...
Native walker are triggered with <code> walk() </code> method and are not set up to receive data on creation. You can define custom property and constructor method for this purpose: <code> class plus_walker extends Walker_Nav_Menu { var $refine; function __construct($refine) { $this-&gt;refine = $refine; } } //stuff 'w...
How do I pass an argument to my custom walker?
wordpress
i'm writing some custom wordpress pages, and i want that after an action where the user has addess an item to a list (after the user press the submit button and the page reloads showing the updated list) a messagge appears on top of the content area saying something like "the item xxxxxxx has been added." and then fade...
WordPress makes use of <code> add_settings_error() </code> and related function to setup notifications to display. Using them is not very straightforward, so easier way might be to make use of hooks like <code> admin_notices </code> or <code> all_admin_notices </code> to output your own message and style it in same way...
"operation successful" message
wordpress
I've been trying for a while now to make it so that there is nothing shown if there are no Related Posts. Currently the headline and the container (of course empty) are displayed. Like I said I tried a lot and I came to the conclusion that it might be too difficult if not impossible to get rid of everything as the code...
I don't see why it would be impossible to do what you want to do. I think you just need to do a bit of rearranging. Put your custom query code first, then put your containing HTML markup inside the <code> if ( $my_query-&gt;have_posts() ) </code> , then put your related-post markup inside the <code> while ( $my_query-&...
Problem with "conditional tag": if empty
wordpress
I know how to create pages automatically when a theme is activated, but I need help to figure out how to also programmatically create child pages at the same time. For example: <code> - Page 1 - Page 1.1 - Page 1.2 - Page 2 - Page 2.1 - Page 2.2 - Page 2.3 - Page 3 - Page 3.1 - Page 4 - Page 4.1 - Page 4.2 </code> And ...
The example by @Tareq was very helpful, but instead of creating multiple child pages for the parent page, it would make each child page a sub-parent page. <code> Page 1 - Page 1.1 -- Page 1.2 --- Page 1.3 Page 2 - Page 2.1 -- Page 2.2 etc. </code> Here is the fixed/improved function (I'm sure that this can be improved ...
How can I programmatically create "child" pages on theme activation?
wordpress
I've been working on this for many, many, many weeks already. I've already asked similar questions here and elsewhere, but nobody seems to be able to sovle this problem. Maybe it's not possible anyways? My related posts are tag based and the code looks like this: <code> &lt;?php $backup = $post; $tags = wp_get_post_tag...
Do you mean you want to display three blocks of four related posts, and flip between the three blocks using scrollable? If so, does the below help (not tested)? Assuming scrollable needs its content in separate divs, you could do something like this. It should produce a containing div with up to three divs inside, each...
Related Posts loop - offset
wordpress
I've been trying to figure this out for many, many days now. I tried to modifiy the code various times, always with the same result. I just don't get it. I want to properly separate pingbacks and comments which I did with the following code: <code> &lt;?php if ( have_comments() ) : ?&gt; &lt;h2 class="h2comments"&gt;&l...
Actually, after trying a lot more I figured out that it was actually something quite simple I just forgot. Apart from the code in the comment.php, you also have to change this in your single.php: <code> &lt;?php comments_template(); ?&gt; </code> to <code> &lt;?php comments_template('', true); ?&gt; </code> And that di...
Comments and pingbacks issues
wordpress
I have a WordPress 3.2.1 site hosted on a DreamHost shared Debian/Apache server. Since I set up the site two years ago, it's been set to the <code> /%year%/%monthnum%/%postname%/ </code> permalink structure. It was also redirecting URLs like <code> /?p=204 </code> and <code> /?page_id=1836 </code> to their "pretty" cou...
Found the following in a plugin file using <code> grep -Ri 'redirect_canonical' /path/to/wordpress/plugins </code> : <code> remove_filter('template_redirect', 'redirect_canonical'); </code> That disables WordPress' built-in canonical URL redirects. Disabling the component of the plugin that contained that line fixed th...
Ugly permalinks stopped redirecting to pretty URLs
wordpress
I would like to suppress the output of one of my custom fields. Is there a way to do this using the <code> &lt;?php the_meta(); ?&gt; </code> command?
The function, <code> the_meta() </code> allows you to hook to the <code> the_meta_key </code> filter (which currently is not documented in the Codex); this is where it fires off: <code> // wp-includes/post-templates.php @line 744 echo apply_filters('the_meta_key', "&lt;li&gt;&lt;span class='post-meta-key'&gt;$key:&lt;/...
Eliminating the appearance of a specific custom field in a post
wordpress
I just migrated a WordPress blog from one host provider to another. Did a clean install on the new server, and everything seems to be working fine except all the permalinks for some reason add a string on the end like this: http://keefermadness.com/2011/09/behind-the-scenes-of-my-nasa-grail-experience-day-one-am#.Tpq5D...
Actually, I just figured it out. In the migration, the settings were slightly different in the "Add This" plugin. I had selected "Track address bar shares" which added the # and the characters for tracking purposes. That is now removed.
Migrating Wordpress blog to New Webhosts, something is adding a # and gibberish
wordpress
So I found some handy snippets to help remove admin menu items. However, I'm having trouble with the sub menu items. I want to keep the appearance menu, but get rid of the Themes, Widgets, and Editor. <code> function remove_menus() { global $menu; global $current_user; get_currentuserinfo(); if($current_user-&gt;user_l...
Try this: <code> add_action('_admin_menu', 'remove_editor_submenu', 1); function remove_editor_submenu() { remove_action('admin_menu', '_add_themes_utility_last', 101); } add_action('admin_init', 'remove_theme_submenus'); function remove_theme_submenus() { global $submenu; unset($submenu['themes.php'][5]); unset($subme...
Remove menus and submenus
wordpress
I am running a custom query below each post, to get other post from its category. Now I want to exclude the current post. This is my Query: <code> &lt;?php // related_posts(); $exclude_post = $post-&gt;ID; $cats = get_the_category(); //$cats[0]-&gt;term_id;$cats[1]-&gt;term_id; //name global $post; $newQuery = new WP_Q...
You are trying to supply an array as part of the string query parameter. You could instead just supply the arguments list as an array like this: <code> $newQuery = new WP_Query( array( 'posts_per_page' =&gt; 5, 'orderby' =&gt; 'rand', 'cat' =&gt; $cats[0]-&gt;term_id, 'post__not_in' =&gt; array($exclude_post) ) ); </co...
Problem with 'post__not_in'
wordpress
I have a situation where I want to add a second custom top-level menu for a custom post type. So, when we have a CPT named "fruits", which registers a top level menu with a label of "Fruits", clicking on "Fruits" will take you to <code> edit.php?post_type=fruits </code> . I'm trying to add a separate top-level menu wit...
Answering my own question as noted in the edit: This actually seems to do the trick, not sure if it's the best way though: <code> add_menu_page('Oranges', 'Oranges', 'edit_posts', 'edit.php?post_type=fruits&amp;subtype=oranges', ''); </code>
Add top-level menu pointing to a different custom post type?
wordpress
Is it possible to make the code below preview a page instead of a latest category post? <code> &lt;div class="one_third_last"&gt; &lt;h2&gt;Gift Vouchers&lt;/h2&gt; &lt;div class="entry"&gt; &lt;?php //The Query query_posts('posts_per_page=1&amp;cat=7'); //The Loop if ( have_posts() ) : while ( have_posts() ) : the_pos...
try and change this line: <code> query_posts('posts_per_page=1&amp;cat=7'); </code> to: <code> query_posts('posts_per_page=1&amp;page_id=17'); </code> or: <code> query_posts('posts_per_page=1&amp;pagename=page-slug'); </code> (enter the actual page ID or page slug into the respective space) http://codex.wordpress.org/C...
How to preview a page instead of a category?
wordpress
I'm bascially looking for something that lets visitors to my page comment on photos. When they hover over the photo the image notes will load. Best would be if those notes would also show up in the comment-list with a thumbnail of the commented photo next to the comment. I know it's possible. I've seen it here . I only...
It sounds like you are asking for two features here: Image annotation Image comments You referenced a plugin for the first, and WordPress supports the second out of the box! As another choice, in the last link you provided, that person is using Flickr to handle their annotations and comments. This is another great opti...
jQuery Image Annotation
wordpress
I have a menu item I created called 'View Certificates' and a sub menu item called 'Add Certificates'. The Add Certificates page is just a file upload page. After the file uploads successfully, I want it to redirect back to the 'View Certificates' page. All my code is in the functions.php file. How do I go about doing ...
You can use wp_redirect <code> &lt;?php $url='something.com'; wp_redirect($url); exit; ?&gt; </code>
Redirect in an Admin page
wordpress
I've added a few custom fields to the WordPress image uploader using the hooks <code> attachment_fields_to_edit </code> and <code> attachment_fields_to_save </code> . Everything works very well, except when a field is erased by the user. For example, the field used to say 'Oil Painting' and the user erased it, wanting ...
You are checking if the field is empty. Try to update it if its empty as well <code> if( trim( $attachment[ $field ] ) == '' ) $post[ 'errors' ][ $field ][ 'errors' ][] = __( 'Error! Something went wrong.' ); else update_post_meta( $post[ 'ID' ], $key, $attachment[ $field ] ); </code> Try <code> if( isset( $attachment[...
Custom field not updating when value is empty
wordpress