question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
Is there any way to add %post_type% and %taxonomy% to permalinks? I want to have links from one custom post type have one taxonomy's terms in its permalink, and another post type to use another taxonomy's terms.
I will try to answer the question in detailed but keeping it as short as possible considering you have achieved the basics. Suppose our custom post type one is to be connected to taxonomy one. Let's call them 'console'(custom post type) and 'brands'(taxonomy). You want to achieve: http://example.com/console/brands/sony...
Use different taxonomies in different custom post types' permalinks?
wordpress
This might be an annoying question, since there are stackexchange-url ("some pretty good answers") to this question, but they are 9 months old, so please but bare with me. I would like to have some input to point me to the right direction. I'm looking to integrate a simple forum for a Wordpress project. The forum must ...
Have you beta-tested the bbPress Plugin? It should meet most of these needs.
Wordpress and simple forums
wordpress
I'm currently in the process of redeveloping my website. I've decided to use WordPress as its CMS, rather than coding everything from scratch. It's a fishkeeping website, consisting of species profiles; plant profiles; fossil species profiles; articles; news posts and blog posts. My original idea was to create plugins ...
Custom post types are an excellent way for this kind of a job. I'd suggest reading the following info: Custom Post Types (1) (2) Taxonomies (1) (2) Custom Meta Boxes (1) - I use this class all the time, or (2) If you are new to Custom post types, an easy way to start would be playing around with Custom Post Types UI pl...
Custom Post Types, or completely custom?
wordpress
If you have created shortcodes in Wordpress, you may have noticed that when you get the content of your shortcode, it's wrapped in html paragraph tags. I don't know why the progammers did that. It seems like a very bad idea to me to add formatting to the actual content. I've found a post that presents this solution : h...
The shortcodes, since they are inserted in the editor, comply to editor rules. Hitting the return in editor will generate a paragraph tag, just like any other text. It's one of the TinyMCE features. To read more about TinyMCE check out their forum and especially this thread
How can i remove the paragraph from shortcodes content?
wordpress
I Want to Add My Latest 5 Post Title with Corresponding Link in My Header Position.What was the Actual Php code?Am Newbie ....
This sounds like an additional Loop on that page, right? You might want to use: <code> &lt;ul&gt; &lt;?php $posts_query = new WP_Query('posts_per_page=5'); while ($posts_query-&gt;have_posts()) : $posts_query-&gt;the_post(); ?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;...
How Can i Get 5 Recent Post Title With Corresponding Link?
wordpress
I am wondering from the syntax <code> $sql = $wpdb-&gt;prepare( 'query' [, value_parameter, value_parameter ... ] ) </code> It appears (from the syntax - values within prepare) that it simple escapes values not craete a prepared statement giving me performance benefits when I execute it multiple times will different pa...
<code> $wpdb-prepare </code> works like <code> sprintf </code> and <code> vsprintf </code> . The first argument will always be a format string. The only acceptable format specifiers are <code> %s </code> and <code> %d </code> . Others I have never tested but may result in parse error as per the Codex. You must escape l...
Does $wpdb-> prepare not create a prepared statement that I can execute multiple times?
wordpress
Suppose I have a post meta like "Region" it will contain values like "Region 1", "Region 2" etc. But it should only contain ONE value. Also I would like it to have an archive page. If I use custom taxonomy, users can select more than 1 value. Is it possible to have a drop down type selection instead?
For mutually exclusive values use post meta. It is faster to read than assigned taxonomies too. It is possible to create your own interface: Set the parameter <code> show_ui </code> to <code> false </code> when you register the taxonomy. Register a meta box where you print out all existing taxons with radio boxes. Add ...
Single reusable value for post meta: Custom Taxonomy or Post Meta?
wordpress
I've got several questions regarding WP multisite, hoping someone who's used it extensively can help: Is it possible to manage several WP sites over several different domains? How can plugins be managed, some I'd like to use across all the sites but others I'd only like to use on certain sites. Also what happens to eac...
Yes. Use the Domain Mapping Plugin. Plugins can be enabled network-wide, or on a per-site basis. You can choose whether or not to give site admins the capability to activate/deactivate Plugins. Plugin settings are on a per-site basis. The Network Administration handles updates to core, Plugins, and Themes, and automate...
Multisite questions
wordpress
I have the default setting (IIRC) of 10 comments per page, and max nesting of 5 deep. The problem (or at least, minor annoyance) is that replies to comments are not counted towards that maximum of ten per page. I can understand that you do not want to break a thread, and that should be avoided, but in my test case I ha...
Since I decided this would actually be pretty damn useful for myself too, I pushed on and wrote a custom walker, <code> Walker_Paged_Threaded </code> . I've tried to comment to the best of my ability, and admittedly it's a little thrown together, but I'm happy with the result. How To Use It The class is written with th...
Nested comments ignored for max per page in wordpress
wordpress
In WordPress localization files (.po), does php map files by the line number eg. <code> comments.php:60 </code> or msgid <code> msgid "&lt;span class=\"meta-nav\"&gt;&amp;larr;&lt;/span&gt; Older Comments" </code> . So basically, if I have said string in comments.php in line 60, and move it to line 74, does it still ge...
if I have said string in comments.php in line 60, and move it to line 74, does it still get localized by the msgid? Yes it does. Localization does not depend on line numbers of strings.
WordPress localization
wordpress
I'm making a theme for a client (first time using Wordpress), and the client would like to have multiple site "descriptions" to be available. The first one as the main description, and the second one as another block of text in the header which can be changed. Is there any way to add such functionality to a theme? I ca...
not 100% sure what you're after but this may help ... i did a site one time and one special set of "pages" on the site were sort of sectionalised ( eg each page consisted of a title and about 4 other "fields" ) .... the way i did it in the back end was to do like dzogchen suggested use custom fields ... so i used the t...
Adding an editable field to template?
wordpress
How can I force WP to always check the child theme folder first when running <code> get_template_part </code> ? Example: child theme loads <code> get_template_part('content', 'inventory') </code> in <code> single.php </code> . Because all child themes (and there are a lot) share the same common inventory template base,...
It does, by default. The <code> get_template_part() </code> function uses <code> locate_template() </code> which cascades through the template files in in order of specificity and stylesheetpath/templatepath. So, if your Child Theme includes a <code> content-inventory.php </code> , then <code> get_template_part() </cod...
How to make get_template_part always check child theme first?
wordpress
I'm missing something here: <code> function page_help($contextual_help, $screen_id, $screen) { if ($screen_id == 'page') { $contextual_help = ' &lt;h5&gt;Shortcodes&lt;/h5&gt; &lt;p&gt;Shortcodes help&lt;/p&gt; '.$contextual_help; return $contextual_help; } elseif ($screen_id == 'post') { $contextual_help = ' &lt;h5&gt...
In order to not delete help from all other screens, you need to always return the contextual help text, otherwise your filter doesn't return anything for non-page/post screens and so nothing will show up. Move the return to the bottom of the function, outside of your if/else. Also, the original contextual help is being...
Issue with contextual help overwriting existing content
wordpress
I am looking for a plugin or a code that will allow admin to select an author and "ban" him from logging in the system and also to unpublish his posted content until the admin decide to allow the entrance again. This should include posts, author page and comments if it is possible. Thank you for your replies.
You could try the User Control Plugin
Plugin to restrict login and unpublish content from an author
wordpress
I was wondering if there is a way or a plugin to post something like twitter update messages instead of a post. Something like http://p2demo.wordpress.com/ but better, where a user will post update messages not an entire post (in database matters). That means you will save space, make it quicker and fewer database reso...
The code you posted is about the same one WordPress uses to insert posts in to the database so it's not really saving anything. But i would suggest you use Custom Post type and only allow a few or as much as needed objects to it : 'title' 'author' 'excerpt' 'custom-fields' 'comments' (assuming you want to allow comment...
Instead of submiting an entire post, is there any way to submit a lite-post or a simple message?
wordpress
I cannot figure out how to make next_posts_link() work within my custom WP_Query. Here is the function: <code> function artists() { echo '&lt;div id="artists"&gt;'; $args = array( 'post_type' =&gt; 'artist', 'posts_per_page' =&gt; 3, 'paged' =&gt; get_query_var( 'page' )); $loop = new WP_Query( $args ); while ( $loop-&...
try passing max_num_pages to the function: <code> next_posts_link('Older Entries »', $loop-&gt;max_num_pages); </code>
WP_Query and next_posts_link
wordpress
I'm trying to have sort of a functionality that will let me find all internal links on my site that are pointing to a page. i.e - I want to know all pages on my site that are linking to (any) page in my site. I tried to find sort of a ready made plugin for that, but didn't seem to find. I can develop one by myself, but...
Post Search Approach Pull out all of your posts and pages from the database Iterate through all pages / posts and do a string search on the content - <code> substr_count( 'http://www.yourdomain.com', $page-&gt;content ); </code> Sum up the counts from all the posts / pages This will of course miss allot of links made b...
How to find all links between pages
wordpress
I was thinking of adding the following lines of code to my <code> functions.php </code> file: <code> /** * Change the default list of allowed html tags */ add_action('init', 'edittag', 10); function edittag() { define('CUSTOM_TAGS', true); global $allowedposttags, $allowedtags; $allowedposttags = array( 'strong' =&gt; ...
Read here about <code> _moz_dirty </code> (Using Google would have given you the same answer - 2nd Result for "_moz_dirty"). Regarding html-stuff: You're offering the ability to add links...
Will my Wordpress site become vulnerable after adding this functions which allows more HTML tags for subscribers?
wordpress
I currently have a new custom post type-- "Books." I have a custom rewrite url that I set when registering my post type: <code> 'rewrite' =&gt; array( 'slug' =&gt; 'books', 'with_front' =&gt; false ) </code> It works great when I visit a specific post, but how do I take control of the /books url for displaying a list o...
Once way of doing it - I am sure there are other ways too - is to make a page template for books: books.php You can make a copy of page.php and rename it. In the top of the file you place the usual Page Template code as in: <code> &lt;?php /* Template Name: Books */ get_header(); ?&gt; </code> Below the normal loop, yo...
Displaying Posts of a Custom Type
wordpress
I got error of "Call a member function embed() on a non-object", but I can see the result of var_dump is an object. Please help evaluate the following code: This is the Class to create a picture: <code> Class Picture{ //.... function embed() {...} //.... } </code> This is the Class for template: <code> Class Picture_Te...
To me it seems <code> Picture_Template </code> is worthless - it's not even correctly formed (you need to place run-time code in a constructor ). Plus you also seem to lack the basic understanding of variable scope (like accessing <code> $post </code> and <code> $obj </code> within functions and classes, without global...
Error of "Call a member function on non object" while var_dump get correct result
wordpress
For some reason, one of my top posts as reported by WordPress Stats is actually non-existent... What I see is: #2147483647 (loading title) and it links to "...?p=2147483647" which returns a 404. Now a bit of background info: I'm actually using the following permalink settings: /%category%/%postname%/ Stats for other po...
Turns out WordPress doesn't deal well with post IDs > 2^31. http://core.trac.wordpress.org/ticket/16445 Tumblr in particular has post IDs greater than this, so it's not recommended to keep old post IDs from Tumblr on an import.
WordPress Stats keeps showing non-existent post as a top post?
wordpress
Is there a way (a common one) to duplicate and change a theme widget ? I'm asking this because, I have this widget that displays the recent news and if we click, it will display ALL news, but I wish to create a new widget that lists the latest articles (posts with a category "articles"), and if we click, that lists ALL...
Widgets extend the Widget Class , search in the theme code for a class that <code> extends WP_Widget </code> . Copy/Paste it, rename it, and change what you'd like. You can also look in the file <code> wp-includes/default-widgets.php </code> and use one of those as a starting point.
Duplicate and change a Theme Widget
wordpress
Ok. Going to try and explain this as best as I can, so bare with me. Anyway, I'm trying to include the default media uploader as a part of my plugin. Currently, I've successfully managed to use the filter <code> attachment_fields_to_edit </code> to hide most of the input fields, leaving only the title &amp; alternate t...
what i ended up doing was launching the thickbox uploaded manually via a jquery click event. then with setInterval i was able to hide the pieces i wanted. jQuery(document).ready(function($) { <code> $('.specialclass').click(function() { //get post id from somewhere (for me this was the row column string = $(this).paren...
Manipulating Media uploader
wordpress
am trying out a bit of ajax ( via jquery ) in wordpresss. ... i have everything working correctly but for some reason i have to have the full url to the php handler file even though it's located in the same directory as the script here's the code $.post('http://full/url/to/file.php', $("#form").serialize(), function(da...
it needs a full URL because even though it may be the right location relatively on the back end, it's not on the same on the front end, at the URL where your page is ultimately served. you're on the right path with <code> wp_localize_script </code> . you want to enqueue your ajax script, then pass the admin ajax url to...
ajax in wordpress - path issue
wordpress
I've been stumbling around trying to figure out how to get a specific taxonomy term of the current page so that I can subsequently populate queries on the page for other post types that share the same term. Basically: Page 1 has taxonomy term - education policy page.php has four parts: standard loop that outputs the pa...
Hm, if you registered a taxonomy for the "page" object type correctly and then assigned a term of that taxonomy to a page... I believe you can then access the taxonomy and term slugs in the following way: <code> get_query_var( 'taxonomy' ) get_query_var( 'term' ) </code> If you <code> print_r($wp_query) </code> you wil...
How to get taxonomy term of the current page and populate queries in the template
wordpress
There must be a solution for this. I am using this solution for chooosing images from media library. http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/ THE PROBLEM: I am using two meta boxes for custom post type “products”. First consists of two metafields what is for addin...
I think you're running into a problem people mentioned in the comments to that story. Someone else posted about it here: http://www.theenglishguy.co.uk/2010/01/24/multiple-media-uploads-in-wordpress-functions-php/ Basically, the JavaScript from that site should be modified to be more like this: <code> jQuery(document)....
Too much recursion error when chosing image from image library for two different meta boxes in one post
wordpress
I had an issue with a server that was serious enough to have to take it completely offline and then rebuild the os. I have gotten to the point where the new server is up and running. I have managed to get all the wordpress files and database files transfered over to the new server. The Problem For some reason wordpress...
Here is the default .htaccess generated by Wordpress for Subdomain Multisite setup: <code> # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # uploaded files RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME}...
Server crashed trying to restore wordpress multisite, images are not found pls help
wordpress
Is there any way to filter all post queries and add a specific taxonomy? Case in point, I have a taxonomy object of "Region" with terms like "Global", "Americas", "Europe", etc. (Users designate their region in their user profile through custom fields which is stored as a usermeta value and added the user cache object....
Below code is an example that does what you want. See tax_query for more information. <code> function my_get_posts( $query ) { // we only need to modify the query for logged in users if ( !is_user_logged_in() ) return $query; $current_user = wp_get_current_user(); // assuming that user's region is stored as user_region...
Filter all queries with a specific taxonomy
wordpress
first of all sorry for my bad english. Let me explain what I`m trying to do: I have a column inside a SQL table with a string using the following format: yy-mm-dd The thing is, it doesn`t use a dateformat type. So, I have my query, where I need to capture all fields with the following specification: value &lt;= '{$this...
<code> $yesterday = array ( 'year' =&gt; date('y'), 'month' =&gt; date('m'), 'day' =&gt; date('d')-1 ); $rows = $wpdb-&gt;query($wpdb-&gt;prepare(*emphasized text* "SELECT id, yymmdd FROM plugin_data WHERE yymmdd LIKE '%d-%d-%d", $yesterday['year'], $yesterday['month'], $yesterday['day'] )); foreach ( $rows as $r ) { $...
Help with wordpress custom query and advanced custom fields plugin
wordpress
I have a family website, private, requires a WordPress account, in WordPress. Some of my family members would like to get the option for notifications of new posts by email or text message. Email seems easy enough, there are plugins and services for that. But I'm concerned about text messages because we are geographica...
I'd say there's three specific requirements here; Allow users to choose notification times, timezone aware Hook into <code> transition_post_status </code> to listen up for new posts, and then take action Find a decent SMS API For 1), hook into <code> show_user_profile </code> to output your time picker field(s), and <c...
Mechanism to send to users of secured WordPress install new notifications by SMS or email?
wordpress
http://adambrown.info/p/wp_hooks/hook/plugin_action_links_%7B$plugin_file%7D Says the hook is deprecated. However, the {$prefix}plugin_action_hook_{$plugin_file} is not. I poked around the <code> wp-admin/includes/class-wp-plugins-list-table.php </code> file for the hook, and found this: <code> $actions = apply_filters...
Yes, both should work as expected: <code> "plugin_action_links_{$plugin_file}" </code> <code> "network_admin_plugin_action_links_{$plugin_file}" </code> Note that I'm using <code> " </code> instead of <code> ' </code> . PS: The term is deprecated , not depreciated.
plugin_action_links Filter Hook Deprecated?
wordpress
I'm using Posts 2 Posts plugin. I've got 2 custom types : movies and actors. I created a movie => actor connection so that for each movie I can see which actors play in. But as far as I understand, in order to find out all the movies a particular actor has played in, you must create an actor => movie connection AS WELL...
To see connections on both edit screens, set <code> reciprocal </code> to <code> true </code> , but note this is for the UI only, it doesn't affect connections otherwise. <code> function my_connection_types() { if ( !function_exists( 'p2p_register_connection_type' ) ) return; p2p_register_connection_type( array( 'from'...
[Plugin: Posts 2 Posts] reciprocal connections
wordpress
I'm doing up a blog at the moment where each post is accompanied by the name of a song. Adding the songs to the posts is fairly easily done via custom fields. However, I also need to have a page which lists all the songs in one place. Can this be done without using a plugin? If so, how? (And if not, then what's the bes...
I suggest using shortcode, as this'll easily allow you embed the song list anywhere in your content, in any page or post. UPDATE: I got a little carried away, and ended up with this! <code> function song_list_shortcode( $attrs ) { $r = ( object )wp_parse_args( $attrs, array( 'format' =&gt; '%post_title - %link', 'link'...
Populating a page with content from post custom fields
wordpress
REQUIRED: Comments are displayed as "Off" while they aren't in wp-admin. Comment form is not displayed in these cases, while it is when a unit test post already has comments. i have installed the Test data . and on some post and comment test post pages. these pages had some comments. and there is also a Comment form un...
OK, I figured it out. It took a bit of digging and many bad suggestions. The solution is actually quite simple. Just replace this in your theme files: Where you have this : <code> &lt;div class="comments"&gt; &lt;?php comments_template(); ?&gt; &lt;/div&gt; </code> Replace it with this: <code> &lt;div class="comments"&...
what's meaning of it when submit a theme?
wordpress
Is there a plugin or snippet that would: Add an email input form to each post Send a predefined message when new media (or attachments) has been uploaded for that post only The requested functionality here is different from other plugins I am aware of because it targets only the end user and only on new media upload (a...
As for the email input form, you can use any plugin for Custom Fields ( I use Advanced Custom Fields or Custom Content Type Manager ) or add you own meta box ( tutorial ). And for sending an email to the address inserted as a custom field, use the following code. The custom field is named email_warn . The filter <code>...
Is email post notify visitor on new media upload possible?
wordpress
Not sure if this is possible, but bear with me. I think I am halfway there. First a little background: I'm using the build in hierarchy in WordPress to form relationships between post types. I have a post type called series that holds info on a TV series. I have another post type called content that has info on specifi...
I did find some solutions to the problems I had above: Red strike through in the Rewrite Analyzer plug in means that the query_var wasn't defined before hand, so WP automagically deletes them. The other problem I had was solved here: stackexchange-url ("Using %postname% tag with a Custom Permastruct creates 400 Bad Req...
Help with a TV series Rewrite structure
wordpress
Having issues showing my post in separate list based on category I have a static home page set my page: "home" and I have the blog set to my page: "Inspiration" I have 2 main categories "inspiration" and "Portfolio" and those catagories are also the titles of my menu items. So I have Home, Inspiration, and Portfolio. B...
i can't able to understand your question,but i guess ,My answer is login as a Wordpress Admin and select settings-> Reading...In There you Select Static Page &amp; Set Front Page and Post page as you want.I think you got Answer.if not means just mention what you want exactly? :)
Seperate WordPress catagories into sepeat list on seperate pages
wordpress
I need to take a site that is installed as a subdomain blog on a multi site install and move it to it's own domain on a standalone wordpress installation. How can this be done? I am running into trouble with the path to the images in posts because multi site uses <code> /blogs.dir/blogid/ </code> Can this be done?
Although I have not tested a use case such as yours. If the trouble is with path to the images in the posts and other you can give WordPress OneClick Migration a try. It was designed with Database level migration but it should work. You may need to run it in forced mood. See the Readme file for full details.
How to convert multi-site to single site
wordpress
I have this code: <code> $args=array( 'public' =&gt; true, '_builtin' =&gt; false ); ?&gt; &lt;select id="&lt;?php echo $this-&gt;get_field_id('posttype'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('posttype'); ?&gt;"&gt; &lt;?php foreach(get_post_types($args,'names') as $post_type) { ?&gt; &lt;option &lt;?ph...
You just need to pull the Labels via <code> get_post_type_object(); </code> <code> &lt;?php $args=array( 'public' =&gt; true, '_builtin' =&gt; false ); $output = 'names'; $operator = 'and'; $post_types=get_post_types($args,$output,$operator); ?&gt; &lt;select id="" name=""&gt; &lt;?php foreach ($post_types as $post_typ...
How to show cutom post labels in options?
wordpress
I want to develop a WordPress theme from scratch. Is there any wireframe tool in which I can design the a complete page and it exports the html/php file against it. I want a free tool.
I personally do not know of any free tool that would achieve what you are looking for. The closest thing would be to use a "slice and chop" company that would take your designs and slice them up for you at a price though. There is a great "blank" wordpress theme out there that I use on all of my projects. It has all of...
Wireframe tool for WordPress theme
wordpress
I'm trying to use contact form 7 on my site. The only server side validation that it seems to do is check if required fields have been entered. Isn't there a danger if someone sends several MB of data through tools like tamper data? Will I need to rewrite the plugin code to take care of validation?
It doesn't take much to tamper data when you use HTML forms; you don't even need a plug-in to do that. That's inherent in all HTML forms. If you're that worried about people tampering with your data, yes, you'll need to rewrite the plug-in code to use session variables or a digital signature.
Server side validation for Contact Form 7
wordpress
I have a field on the admin side where a user enters a number for a price. If a user enters 1000000 I'd like to be able to display on the front-end $1,000,000. Any ideas on how to accomplish this? Edit More details, the post is a custom post type 'property'. To add the meta fields on the back-end I'm using Meta Box Scr...
To format number, you can use the function <code> number_format_i18n </code> (it's not documented now, but you can see its source here ). Its work is format the number based on the language. You might want to look at <code> number_format </code> ( PHP built_in function , and is used by <code> number_format_i18n </code>...
Add dollar sign and commas to a number?
wordpress
Is there a way to code "Restore Defaults" button into a plugin options page? I'm writing a plugin right now that has sets up some default values on activation (via <code> register_activation_hook </code> ), and I'd like to give users the option to restore those defaults again with a click. Possible? Thanks!
Nevermind, answered my own question: http://www.keyframesandcode.com/resources/javascript/jQuery/demos/populate-demo.html Used that to update all the text and drop downs. Couldn't get it to work with my checkboxes, but a few other lines of jQuery took care of those. I like the idea of just auto filling the form with th...
Restore a Plugin's Default Settings
wordpress
In the get_blog_excerpt() function below, the excerpt_more filter works perfectly when the post excerpt is not present, however, when the post has an excerpt, I'm not getting the "Read More" link. I understand that the_excerpt first checks to see if a post excerpt is present, which is fine, but I want the read more lin...
I'm going to assume that you're calling <code> get_blog_excerpt() </code> in your template somewhere? If so, what happens if you simply call <code> the_excerpt() </code> , and then pull the two <code> add_filter() </code> calls out of the container function? i.e. <code> functions.php </code> would just look like: <code...
How to make the excerpt_more filter apply to the actual post excerpt?
wordpress
Hi to all I'm trying to create a function that can ECHO the excerpt of a random post from a choosen category. What I did up to now is: <code> &lt;?php function $titoloslide() = { query_posts(array('orderby' =&gt; 'rand', 'category_name' =&gt; 'testimonianze', 'showposts' =&gt; 1)); if (have_posts()) : while (have_posts...
cleaned up syntax errors: <code> &lt;?php function titoloslide() { query_posts(array( 'orderby' =&gt; 'rand', 'category_name' =&gt; 'testimonianze', 'posts_per_page' =&gt; 1 )); if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;div class='testimonianzefurgonihome'&gt;&lt;a href='#' title='Testimonianze n...
Function to show random posts from a category
wordpress
I have my plugin all set-up using the Settings API and working but what I have is two manual functions in my plugin that can be run by the admin user by visiting the following URL's <code> &lt;?php echo admin_url(); ?&gt;options-general.php?page=wordpress-file-monitor-plus&amp;sc_wpfmp_action=1&amp;sc_wpfmp_scan=1 &lt;...
Why does the Settings API send those parameters when submitting the settings form? Quite frankly, it doesn't. As you already mentioned, your form simply POST's to <code> options.php </code> , which in turn handles the request, updates the database, and then redirects back to the referer . How the referer is fetched is ...
GET parameters interfere with my plugin settings
wordpress
I am trying to get three loops to display. they all belong to the same post type and the same taxonomy family. but i'm trying to separate the taxonomy by three different values. <code> $argsOwners = array( 'tax_query' =&gt; array(array('taxonomy' =&gt; 'position', 'field' =&gt; 'slug', 'terms' =&gt; 'senior-management'...
As @TheDeadMedic said, you've to work like that. in the default loop like: <code> while( have_posts() ) : the_post endwhile; </code> in this case, the loop is running with the default <code> $wp_query </code> variable. But as you are running custom queries, you need to use <code> while( $query_obj-&gt;have_posts() ) : ...
cannot get multiple loops using tax_query
wordpress
I need to build a php foreach that goes through all my terms in my custom taxonomy 'Section'. I know how to get a foreach of all the terms in 'Section', but what i cant do is build it with levels. I want the top parent term to be the heading, and its children will be displayed in a list. Heres an html example of the ou...
I managed to work on it a little more and built the answer myself. Heres the code i needed. <code> &lt;?php $parent_terms = get_terms('section', 'orderby=name&amp;hide_empty=0&amp;parent=0'); foreach ( $parent_terms as $parent_term ) { ?&gt; &lt;div class="accordian open"&gt; &lt;div class="accordian-title module-gradi...
Leveled - Terms foreach
wordpress
I tried using wp_list_categories, but that just gives me a list of the categories. I currently have this code in my category-recipes.php file: <code> &lt;ul class="subcats-list"&gt; &lt;h2 class="subcats-title"&gt;&lt;?php echo get_cat_name(38); ?&gt;&lt;/h2&gt; &lt;?php $recipes = new WP_Query(); $recipes-&gt;query('s...
Use get_category_link. Your code (relevant part) will look like: <code> &lt;h2 class="subcats-title"&gt;&lt;a href="&lt;?php echo get_category_link(38); ?&gt;"&gt;&lt;?php echo get_cat_name(38); ?&gt;&lt;/a&gt;&lt;/h2&gt; </code>
Need category header to link to category archive list
wordpress
I would like to add a public profile page to the authors and others contributors in my site. where visitors can see their profile info. I don't wanna use Buddypress, is it possible with WordPress alone?
bainternet posted something in this thread that will help you, (this is actually editing user profiles from frontend) but it will give you the idea, then just echo the fields out on author.php
How to create a public profile for authors/contributors/users?
wordpress
I have a script in archive.php, which is outside the loop, that calls on the function get_blog_links() to list all posts that belong the the current category (my "blog" category). I'm trying to do some trace testing inside the "get_blog_excerpt() function in order to write out either the post excerpt or (if no excerpt ...
I think you have to <code> setup_postdata() </code> with <code> get_posts() </code> to get things that rely on global variables to work. or explicitly pass the post id with the function.
How to obtain a reference to the_excerpt() from custom loop
wordpress
My understanding is that <code> site_url() </code> returns the location where the wordpress core files are. So, if my blog is hosted at <code> http://example.com/blog </code> then <code> site_url() </code> returns <code> http://example.com/blog </code> But then how does <code> home_url() </code> differ? For me, <code> ...
You are asking two questions at once: What's the difference between <code> home_url() </code> and <code> site_url() </code> ? How do I get WordPress to return the URL root without the subdirectory where it's installed? Here are the answers, and I confirmed with Andrew Nacin, a core developer of WordPress, as well as ra...
What's the difference between home_url() and site_url()
wordpress
Is it possible to call the_excerpt() with tags intact? I'd like to create a excerpted listing of my posts in a specific category, but I'd also like the links and formatting carried over from the post content. I'm currently using the_excerpt() which otherwise works fine, however, the tags are stripped out. I can't find ...
Actually, I just did something like this for a Drupal site. I based my truncation function on this: Truncate text preserving HTML tags with PHP Use the final version of the function at the end of the comments. The function takes its <code> $length </code> parameter in characters, not words, but you can probably use the...
How to call the_excerpt() with tags or the_content() as an excerpt?
wordpress
<code> get_categories() </code> and related functions, by default, don't return empty categories - categories with no posts. I thought that, since there may be some underlying code checking the post counts, is it possible to additionally filter that list to only include categories that themselves contain posts that hav...
Check out my answer on stackexchange-url ("how to get terms that are associated with others through the posts that they're attached to"). In your case, you could put it into practice like so; <code> $category_IDs = get_terms_soft_associated( 'category', array( 'taxonomy' =&gt; 'post_tag', 'field' =&gt; 'slug', 'terms' ...
When using get_categories or similar, is it possible to filter results that contain certain Tags as well?
wordpress
Not sure when it happened but the custom permalinks for pages on my client's Wordpress site have broken. I can fix it by reverting back to the default permalinks and then using the custom permalinks, but they break again whenever my clients edits a page. Blog posts, archives, tags, categories, and custom post types per...
I figured this out. I was using the Custom Post Type UI plugin and had generated the following code (which I added to the functions file) for a custom taxonomy through the plugin: `register_taxonomy( 'video_type',array ( 0 => 'video',) ,array( 'hierarchical' => true, 'label' => 'Type','show_ui' => true,'query_var' => t...
Broken wordpress permalinks on pages only
wordpress
With the following code (in functions.php) my posts (of CPT event) are ordered by _end_date instead of _start_date. What's the proper solution to this as of WP 3.1.3? Of course I'd like to avoid using deprecated <code> meta_key </code> . <code> add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $quer...
This seems to be a bug in Wordpress. Wordpress actually modifies the meta_query if you specify orderby and meta_key as query vars. Normally this modification adds the new meta_key as the first array in meta_query array and hence the orderby is applied to the first meta key specified in meta_query. But when you modify o...
Using meta_query, how can i filter by a custom field and order by another one?
wordpress
Does anyone know of a plugin that is capable of merging the post meta from one post into another? I'm working on re-releasing the Driftwood contact manager theme and I'm trying to find a way to solve the duplicate contact issue. Obviously this question could impact far more people than just myself. :)
<code> /** * Merge metadata from one post to another. * * @param int $from_ID Source post ID * @param int $to_ID Target post ID * @param bool $overwrite Whether to overwrite metadata if the key already exists * @return bool|array */ function wpse_20231_merge_postmeta( $from_ID, $to_ID, $overwrite = true ) { // get ALL ...
Merge posts plugin?
wordpress
I am getting errors like <code> Warning: explode() expects parameter 2 to be string, array given in /data/www/ae/wp-includes/query.php on line 2390 Warning: in_array() expects parameter 2 to be array, null given in /data/www/ae/wp-includes/query.php on line 2399 Warning: in_array() expects parameter 2 to be array, null...
Installing the hotfix plugin may help to solve the problem. http://wordpress.org/extend/plugins/hotfix/ Currently I am using wordpress3.1.3 and got same type errors while browsing the media(media list page) in admin panel and hotfix plugin solves that.
Errors in Add Image Popup, Media Library Tab: "in_array() expects parameter 2 to be array, null given in wp-includes/query.php"
wordpress
I have a wp_query for a custom post type: events. I have a seven day calendar that is showing featured events on a page. Here is the wp_query and supporting code: https://gist.github.com/1030760 you can see the calendar at seattleite.com/calendar/ the thing works great with one exception. It should be showing a feature...
If anyone comes across this question. WordPress Codex says the following to <code> 'orderby' =&gt; 'meta_value' </code> and the <code> order </code> param: Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than...
How does order=asc effect a wp_query (its acting pretty weird in a loop)
wordpress
The WordPress Transients API makes it easy to save expensive values and look them up later. If you install an object backend (such as APC object cache, memcache or W3 Total Cache) you can cache these values between requests, gaining even more. But I've noticed that when the name of a transient field is too long, it sim...
A transient that doesn't expire has a max name length of 53 characters yet a transient that does expire has a max name length of 45 characters. http://core.trac.wordpress.org/ticket/15058
Transient / object cache maximum key length
wordpress
Is there a dedicated WP function, action or filter to use when adding/modifying the HTTP headers? For now I just hook a PHP header() call into the WP 'init' hook like this: <code> add_action('init', 'add_header_xua'); function add_header_xua(){ if(!is_admin()){ header('X-UA-Compatible: IE=edge,chrome=1'); } } </code> B...
The init action is the wrong place to do it. A better place would be at template_redirect, so that you only affect the front end view of the site and not the admin areas.
WP function/filter for modifying http headers?
wordpress
I'm a little stuck here. I have a menu in Wordpress with some posts in it. What I would like is to retrieve all the posts as objects. I think I'm pretty close, but the SQL query doesn't seem to work as I want. This is wat I have so far: <code> $querystr = " SELECT wposts.* FROM wp_posts wposts LEFT JOIN wp_postmeta wme...
I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the wp_get_nav_menu_items() function that helped me. I finnally came with this, 220 was my menu_id <code> $navcat = wp_get_nav_menu_items('220'); foreach ...
Get posts by menu ID
wordpress
I'm trying to figure out how to create a translation for a post using the internal WPML API ( <code> inc/wpml-api.php </code> ) I simply want to create a translation for post ID xx, set some content and publish it. I've tried to play around with <code> wpml_add_translatable_content </code> but couldn't get it right. Un...
I came up with a function that does the job for now : <code> /** * Creates a translation of a post (to be used with WPML) * * @param int $post_id The ID of the post to be translated. * @param string $post_type The post type of the post to be transaled (ie. 'post', 'page', 'custom type', etc.). * @param string $lang The...
[Plugin WPML] : How to create a translation of a post using the WPML API?
wordpress
I just updated to 3.1.3 and now when I go to the admin I get the "Database Update Required" <code> /wp-admin/upgrade.php </code> screen. I click 'Upgrade Now' and it says it's done, but then trying to access anything in the admin gets me the same screen again. How do I get past this? EDIT: In trying to use toscho's sol...
Discovered that the db files I copied over from another machine had incorrect ownership. Once I <code> chown -R mysql:mysql myblogdbdirectory </code> and restarted MySQL, the database upgrade worked.
Site stuck in "Database Update Required" loop
wordpress
Im trying to use the_excerpt form inside a plugins template file, plugin is wp-favorite-posts by default the plugin only lists and displays the saved post title, i have manged to get it to show everything, tax terms, image etc but having a heck of a time with the_excerpt, what happens when i add <code> &lt;?php the_exc...
You are doing few things wrong: the_excerpt does not uses post id. When you modify global $post you should always set it back to its original value. you were assigning get_post's return value to $p which was not used in your code. I have made few fixes in your code. The below code is just the copy paste of your code wi...
Calling the_excerpt from inside a plugin template file
wordpress
I'm using More Fields to create some meta boxes on my custom post type. Is it possible to have a caption for each "group" of fields in the More Fields options? I would like to provide some basic information on the post edit screen. I see you can enter a caption for each individual field but it would be handy to be able...
At this point in time I would just as soon not use the More Fields plugin at all, as there are native functions that can do everything you probably want with custom fields. There seems to be no good documentation afoot and the plugin site is obviously not being updated. Alternatively, try WPAlchemy . Quite easy to make...
Captions for More Fields groups, not just individual fields
wordpress
I have a error handling mechanism setup in one of my plugins to add notices and errors to the admin area, just like the core does. It works fine in most cases, but there are some situations (like saving a custom post type) where it doesn't. I'm guessing that a redirect is happening behind the scenes, and the messages a...
There are few things that I have pointed out in the code below too: You were overwriting the options read from <code> get_option </code> using <code> array_merge </code> You had hard-coded the Message Counts. saving options in <code> __destruct </code> just does not work. (I don't have any clue yet, may be experts will...
Custom admin_notices Messages Ignored During Redirects
wordpress
Suppose I have content like <code> [xxx] Here is some content in xxx [/xxx] Here is content outside xxx ... </code> Can I somehow just get content inside <code> [xxx] </code> ONLY content outside <code> [xxx] </code> ONLY
Depends on the shortcode. If you have access to the shortcode's handler function, that function's second argument is the content inside the shortcode: <code> function wpse20136_shortcode( $atts, $content ){ // $content has the content inside xxx } register_shortcode( 'xxx', 'wpse20136_shortcode' ); </code> For getting ...
How can I just get content inside a shortcode or just outside
wordpress
I'd like to run some code only if a gallery (inserted with the <code> [gallery] </code> shortcode) has been inserted into a post/page. I did the following: <code> gallery_shortcode($post-&gt;ID) ? $gallery = 1 : $gallery = 0; </code> However, this always sets <code> $gallery = 0 </code> whether there's a gallery or not...
try : <code> if (strpos($post-&gt;post_content,'[gallery') === false){ $gallery = 0; }else{ $gallery = 1; } </code>
Check if post/page has gallery?
wordpress
I have previously asked about How to automatically send email to Admin when a user/member changes his/hers profile data. And got some very good answers. stackexchange-url ("Send automatic mail to Admin when user/member changes/adds profile.") Now a follow up: I only want to send/email the data (profiledata) that was up...
So, as Bainternet notes, you would need to compare the new field value to what it was right before the edit. In essence, you will need to build in version control for the profile fields. You will need to add a database table to store this info, using the the <code> $wpdb </code> object to write, and read from it. Basic...
Send email to Admin when user/member updates specific user/member data
wordpress
EDIT: This used to be How do I force a page to be <code> is_archive == true </code> ? I was trying to solve the wrong problem. Instead of forcing the post/page to have a particular attribute, I should have looked at the classes applied to the menu item. The 'Blog' menu-item has the <code> current-page-ancestor </code> ...
As per the change in the question, the answer to this is: Look at the css classes that are applied to the menu-item of interest. The menu-item which this page should be a child of should have <code> current-page-ancestor </code> applied to it. Make the appropriate changes in your styling sheet to style the menu when th...
How do I highlight the menu for a child page?
wordpress
I'm looking for a specific type of gallery plugin implementation. First of all, it needs to be able to pull from Picasa. Second, I would like it to basically be a static lightbox...and what I mean by this is: Single image displayed with previous/next buttons Able to display the image title/description Able to display <...
Picasa plugin i think it'll help you,or help to start a new plugin with some ideas..
jQuery gallery plugin to interface with Picasa
wordpress
I wanted to insert a form with a line of PHP code via shortcode. I am wondering if it's allowed? Has anyone tried it? Take the following for example: <code> function get_form($atts) { return '&lt;form method="post" action=""&gt; &lt;input type="input" name="myinput" value=""&gt;&lt;/input&gt; &lt;input type="hidden" na...
<code> $current_user </code> isn't declared in the scope of that function. You'd want to modify the code to be more like this: <code> function get_form($atts) { $current_user = wp_get_current_user(); return '&lt;form method="post" action=""&gt; &lt;input type="input" name="myinput" value=""&gt;&lt;/input&gt; &lt;input ...
Insert PHP code via shortcode?
wordpress
I was wondering if it would be possible to embed an html page or add an iframe into a dashboard widget. I have a multi author blog and i want to make my admin section a simple as possible for some of my author's are less "technical". So I already added a simple widget containing some text. And I took out the less inter...
Sure, you can do this. It sounds like it would make more sense to add a protected forum to your installation though... but here's how you would do it: <code> // Create the function to output the contents of our Dashboard Widget function iframe_dashboard_widget_function() { // Display whatever it is you want to show ech...
Embed iframe or html page into dashboard widget
wordpress
I am encountering the same problem described here: Unable to set path . In every module where I can edit a page, a <code> p </code> appears after the word 'Path'. I can click on it; clicking on it highlights some of the text. How do I fix this issue?
The path in the editor is just for reference, most of the time users do not even bother looking at it and those that do use if to see what html tag there are in. Example: <code> &lt;p&gt; This is just a sample paragraph &lt;/p&gt; &lt;span&gt; This is just a sample span &lt;/span&gt; &lt;blockquote&gt; This is just a s...
How do I fix my 'Path' field when editing pages via the Dashboard?
wordpress
I want to make a TV Show database in Wordpress that has this URL format: <code> /tvshows/friends/01/12/ </code> <code> /tvshows/ </code> would list all series <code> /tvshows/friends/ </code> would list all the seasons available for Friends TV Show <code> /tvshows/friends/01/ </code> would list all episodes of Friends ...
First, you shouldn't do this with the built in post types of <code> post </code> or <code> page </code> . Use a custom post type. Example: <code> movies </code> and <code> series </code> , where <code> movies </code> is non-hierarchical, but <code> series </code> is. Use register_post_type() </code> and set <code> hier...
TV Show database - Best way for structuring it?
wordpress
I'm trying to add a metabox to select a sidebar per page. In order to create the metaboxes I use this class The construction is fairly easy: <code> $meta_boxes[] = array( 'id' =&gt; 'sidebars_side', 'title' =&gt; 'Page Sidebar', 'pages' =&gt; array('page', 'post'), 'context' =&gt; 'side', 'priority' =&gt; 'low', 'field...
The class you are using accepts value => name pair in the select options array so <code> foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { $sidebar_options[$sidebar['id']] = $sidebar['name']; } </code> and then you can use <code> $sidebar_options </code> .
List all sidebars in metabox
wordpress
The WP source shows that <code> wp_filter_kses </code> and <code> wp_filter_post_kses </code> are passed data that's "expected to be escaped with slashes." On the other hand, <code> wp_kses_data </code> is passed data that's "expected to not be escaped" and <code> wp_kses_post </code> has code that looks like wp_kses_d...
From the codex: wp_filter_kses should generally be preferred over wp_kses_data because wp_magic_quotes escapes $_GET, $_POST, $_COOKIE, $_SERVER, and $_REQUEST fairly early in the hook system, shortly after 'plugins_loaded' but earlier then 'init' or 'wp_loaded'. The first set is then preferred. More of a question of, ...
Which KSES should be used and when?
wordpress
Is it possible to have WordPress email the site administrator whenever a PHP error message is displayed? Ideally the message would also be filtered out of the HTML output, so as to avoid information disclosure. I ask because, while <code> @ini_set('display_errors', 0); </code> is at the top of my <code> wp-config.php <...
Displaying PHP errors isn't really a WordPress thing, it is more of a PHP thing directly. No, I don't think you are crazy for wanting this, I had a similar need for a separate application and I wrote this blog post which should be helpful. Essentially, define your own error handler.
Can WordPress email the admin about PHP errors, while hiding them from the site?
wordpress
I have Press Release Section on my page where i would like to be able to add documents pdf, ms doc's etc. Every time when i add new document to a post I would like download button to appear so user will be able to download that document. Could anyone point me at right direction or maybe there is a plugin existing which...
No need to insert the download into the post as @kaiser says, you can automate: <code> $download = get_children( 'post_type=attachment&amp;post_mime_type=application/pdf&amp;post_parent='.$post-&gt;ID ); if ($download) { foreach ( $download as $attachment_id =&gt; $attachment ) { echo '&lt;a href="'.wp_get_attachment_u...
Downloadable Documents
wordpress
How would I go about not letting empty data into wordpress? <code> &lt;?php foreach($_POST['eirepanel_inline_ads_options_name'] as $post_eirepanel_inline_ads_options_name): if(empty($post_eirepanel_inline_ads_options_name)): echo 'empty'; else: update_option('eirepanel_inline_ads_options', $_POST); $eirepanel_inline_ad...
More importantly, you should not let *untrusted, unsanitized $_POST data* into WordPress. But I think the issue is that you're updating the option with the entire $_POST data, instead of the appropriate array key: <code> update_option('eirepanel_inline_ads_options', $_POST); </code> Should probably be something like: <...
WordPress: update_option, don't update empty options?
wordpress
I have a contact form that I used lot's of times before on other non WP sites but it doesn't seem to work on my current WP site, it just redirects you to a page not found. I don't want to use any plugins to create it. Here's the code: <code> &lt;form class="form" method="POST" action="&lt;?php the_permalink(); ?&gt;"&g...
When dealing with forms you need to make sure that your form doesn't have a few specific filed names like: name,day,month,year and I'm sure that a few more, so make your form fields names more specific like: contact_name,contact_day,contact_month,contact_year. in your case change <code> name="name" </code> to anything ...
Contact form redirecting to page not found on send
wordpress
I have several custom taxonomies and within two of those ( Company Categories and Photographer Categories ) I have a term that is similar. The Company Category called Boudoir and the Photographer category called Boudoir Photographers. When I created the Boudoir Photographer term in the Photographer Categories it rename...
They are all in your <code> {wpdb-&gt;prefix}_terms </code> table and therefore need to be unique. Else you could only get them via ID.
Why does WP rename similar "term name"-slugs in separate taxonomies?
wordpress
I created a self-hosted WordPress blog (on Dreamhost) several years ago. I've never truly been happy with the name and URL/domain of the blog, and I've decided that I want to change it. Here's what I'd like to do: Register the new domain name. (Say www.newblog.com for example.) Redirect traffic from the old domain name...
Every thing you need is covered in the codex Moving WordPress entry.
Changing Wordpress blog name and web address
wordpress
I'm using this code to list the image attachments of a post: <code> &lt;select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;"&gt; &lt;option value=""&gt;Select&lt;/option&gt; &lt;?php $args = array( 'numberposts' =&gt; -1, 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'post_type' =&gt; 'attachm...
I would strongly advise against using <code> $post-&gt;guid </code> - WordPress now generates them in the form; http:/example.com/?attachment_id=ID Use the same method that many of the attachment-related functions use; <code> $filename = basename ( get_attached_file( $data-&gt;ID ) ); </code>
How to get attachment file name not attachment URL
wordpress
I created a meta box I notice that <code> save_post </code> seems to be triggered when I land on the page, thus giving me errors like <code> Undefined index: xxx in /data/www/ae/wp-content/themes/xx/functions.php on line 121 </code> <code> add_action('save_post', function($id) { if (defined('DOING_AUTOSAVE') &amp;&amp;...
See stackexchange-url ("Why does save_post action fire when creating a new post?") You're getting the error as you need to check for the existence of <code> $_POST['xxx'] </code> , rather than just checking if <code> $_POST </code> is set (it will always be set &amp; an empty array by default). <code> add_action('save_...
Why is save_post triggered even when I havent saved the post
wordpress
I find myself creating pages just as a "placeholder" to a listing page. eg. I create a page "Blog" and "Portfolio". Both has the editor emtpy. And I just use it so that I can use <code> page-blog.php </code> and <code> page-portfolio.php </code> for the respective listing pages. It doesnt seem proper? Is there a better...
I guess another way would be including <code> 'has_archive' =&gt; true, </code> into your register_post_type array and using archive-{posttype}.php to style your custom post type listings
Is it proper to create a page just to generate a listing page (eg. for a custom post type)
wordpress
Feedburner won't read your feed if it's over 512k. Our podcast (http://herdingcode.com) has been around for 3 years now, and returning all items puts us way over that limit. We've had new listeners request that we include them all, though, and I'm wondering if that's easily possible. I'm thinking I could hack around wi...
Dunno if you have images in your feed, but those could be sucking up a bit of space: stackexchange-url ("Reducing image size in RSS only") Here are the basics for setting WP to use a custom feed template: http://www.456bereastreet.com/archive/201103/controlling_and_customising_rss_feeds_in_wordpress/ Here are some tips...
How can I minimize the content of my RSS feed to fit more items in Feedburner's 512k limit?
wordpress
I'm not sure if I have done this correctly. As I understand it: if I have a class foo and a static method bar I can register that as the callback by passing the array <code> array("foo","bar") </code> as the function name. If I have an instance of a class in $foo and want to call the method bar I pass the array <code> ...
If I need to register an action inside the class itself would it work with <code> array($this, 'bar') </code> ? Yes, it works. <code> $this </code> Docs is referring to the concrete instance needed for the callback . That's exactly like the <code> $foo </code> example you give. It's just that <code> $this </code> is bi...
Registering Class methods as hook callbacks
wordpress
I'm trying to automatically create terms in a certain taxonomy when a certain custom post type is published. The newly created term must be the name of the post that was published. Example: I have a custom post type "country" and a custom taxonomy "country_taxo". When I publish a country say "Kenya" I want a the term "...
You're almost there - the problem is you're trying to access the <code> $post </code> object when the function only receives the post ID . <code> add_action( 'publish_country', 'add_country_term' ); function add_country_term( $post_ID ) { $post = get_post( $post_ID ); // get post object wp_insert_term( $post-&gt;post_t...
Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!
wordpress
Suppose I have a Custom Taxonomy "Fruits". I want to query for all the values available eg. Oranges, Apples, Mangos etc. How can I do that?
Use <code> get_terms($taxonomy, $args) </code> <code> $terms = get_terms('Fruits'); </code> Codex page
How can I query for all values of a custom taxonomies?
wordpress
I've been trying various ways of doing this. Basically, I've been trying to make it so that a plugin of mine populates the terms of a taxonomy only once during the plugin's activation. The term populating is done in a function via the wp_insert_terms function. Calling the function straight inside the register_activatio...
Here is the fixed version of your code. <code> class vsetup { function __construct() { register_activation_hook(__FILE__,array($this,'activate')); add_action( 'init', array( $this, 'create_taxonomies' ) ); } function activate() { $this-&gt;create_taxonomies(); wp_insert_term('Action','genre'); wp_insert_term('Adventure...
Inserting Taxonomy Terms During a Plugin Activation?
wordpress
So, i got this code to retrieve the images inserted in a gallery within a post: <code> &lt;?php $args = array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; -1, 'post_status'=&gt;'inherit', 'post_mime_type' =&gt; 'image', 'post_parent' =&gt; $post-&gt;ID, 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC' ); $atta...
that's your nivo-slider at work
Getting attachment images is cloning some of them
wordpress
All I understand about RTL is that some languages are written right-to-left. In a WordPress theme, what role does the <code> rtl.css </code> stylesheet have? I was under the impression that the only difference was paragraph alignment, but the WordPress themes that I have seen have massive <code> rtl.css </code> files. ...
This guy explains it fairly well for wordpress (video, no transcript): Yoav Farhi: Right to Left WordPress . The Wordpress Manual (Codex) has as well some information regarding Right to Left Language Support .
RTL Stylesheet Confusion with WordPress
wordpress
Is there anyway to get wordpress to automatically switch locales based on the HTTP Accept-Language header? Similar to how ASP.NET can do it with their globalization="auto" config setting. The reason for this is that I want my dates to be custom formatted based on where you are viewing the site from - not what the wordp...
that's going to be a bit tricky since WordPress doesn't relate date and time format to language. so to get the current language from the browser you can use <code> $_SERVER['HTTP_ACCEPT_LANGUAGE'] </code> and then based on that you can change the date format: <code> function update_date_format(){ $lang = substr($_SERVE...
Wordpress Locale Switching on Accept-Language Header
wordpress
In the codex for WP_Query I see you can query by 'page_id=7' for pages or by 'p=7' for posts... is there a way to get a 'post of any post type' by ID? like 'id=7'—that will get it no matter if it's a page, post or custom post type? I can only get WP_Query with p=7 to work if I add &amp;post_type=customposttype. Is ther...
'any' should retrieve any type: <code> $args = array( 'p' =&gt; 42, // id of a page, post, or custom type 'post_type' =&gt; 'any'); $my_posts = new WP_Query($args); </code>
WP_Query by just the id?
wordpress
I have a function to display the children of the page in the sidebar php file using wp_list_pages: <code> global $post; ?&gt; &lt;div id="subChildren"&gt; &lt;?php if($post-&gt;post_parent) $children = wp_list_pages("sort_column=menu_order&amp;title_li=&amp;child_of=".$post-&gt;post_parent."&amp;echo=0"); else $childre...
you really shouldn't use <code> query_posts() </code> for anything other then the main query of the page. Instead you should use wp_query() or get_posts() , also since you return a value before running wp_reset_query() then its never actually being reset. so change your shortcode to this: <code> function casestudy_shor...
post var problem with shortcode loop
wordpress
I want to ban people or limit registering on unique national ID (You can think it as 11 digit number). Is there any plugin or a code snippet you know? Site will based on MultiSite + BuddyPress. Update: I am not looking for IP ban. You can think it like phone number.. And every user must have 1 unique phone number and i...
first of all, thanks a lot for every answer and everyone who thought a solution for this. my best possible solution without changing too much thing: As i said in a comment, i will use http://www.gravityforms.com/add-ons/user-registration/ for registering. This plugin working even you disable wordpress user registeratio...
Using a number for limiting registering or banning on multisite
wordpress
I'm trying to determine if a piece of content can be edited by a user. I would like all roles contributor and above to be authorized by a single check. Here's my code: <code> if( empty( $post_id ) || !current_user_can('edit_post', $post_id) ) { return; } </code> Unfortunately, the only users that don't get the <code> r...
And the correct capability name is <code> edit_posts </code> . So the correct way of using <code> current_user_can </code> will be like following: <code> if( empty( $post_id ) || !current_user_can( 'edit_posts' ) ) { return; } </code> UPDATE: I have removed the wrong statement, but as the asker mentioned he would like ...
Why does this check to see if user is authorized to edit a post fail for all but super admins?
wordpress
I have three columns, each displaying 2 posts, each from different categories and each being a new query. These three columns are shown on thier parent category page, which is set to display 6 posts per page. <code> $soundPosts = new WP_Query('posts_per_page=2&amp;cat=4&amp;paged=' . get_query_var( 'paged' )); $viewsPo...
OK this is what I ended up with, that works well: <code> // get paged value. $paged = get_query_var( 'paged' ); $maxPages = array(); $max = 0; // Create the queries $soundPosts = new WP_Query('posts_per_page=1&amp;cat=4&amp;paged=' . $paged); $viewsPosts = new WP_Query('posts_per_page=1&amp;cat=5&amp;paged=' . $paged);...
3 Columns, 3 Categories, One Archive, and Pagination
wordpress