question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
My theme and Qtranslate plugin have a conflict and cause many issues on my website's post titles. I cannot trace what causes the issue and I thought that I could handle the title saving myself instead. I would like to be able to change post title that wordpress uses when saving a post from backend. How can I do that?
You can hook into <code> wp_insert_post_data </code> and change things. <code> &lt;?php add_filter('wp_insert_post_data', 'wpse67262_change_title'); function wpse67262_change_title($data) { $data['post_title'] = 'This will change the title'; return $data; } </code> Obviously you're going to have to some checks and stuf...
Change post title during post saving process
wordpress
I'm using this piece of code to list users and their information. The problem I'm having is that the description isn't showing. Obviously it's because the description lays under "user_meta" and not "users". But how would I solve that? <code> &lt;?php $blogusers = get_users('include=2,3,4,5,6,7,8'); foreach ($blogusers ...
The Native get_users() function returns an array of user objects and each on holds <code> [ID] =&gt; 1 [user_login] =&gt; admin [user_pass] =&gt; $P$Bxudi6gJMk2GRt2ed3xvZ06c1BPZXi/ [user_nicename] =&gt; admin [user_email] =&gt; admin@host.com [user_url] =&gt; http://localhost/ [user_registered] =&gt; 2010-06-29 07:08:5...
How to get the user description with get_users?
wordpress
I'm building a WordPress theme, using Roots as a starter theme. Are there any tutorials telling me how to build a theme off of Roots? I've worked with starter themes before, but this one is a whole new monster. I don't know what I'm supposed to edit, and what I'm not supposed to edit.
Roots theme comes with a nice set of Docs https://github.com/retlehs/roots/tree/master/doc but if you want to make sure you don't overwrite something important or want to keep updating your theme then you should create a child theme.
Beginner Resources for Roots Theme Framework
wordpress
I'm just wondering is it wise to delete all post revisions and autosaves from database every once in a while? I mean they take a lot of database space and apparently have no use after the post has been published.
It all depends on your workflow. If you have no use for the post revisions and autosaves then disable them in wp-config and WordPress will clean them up on its own. You may also prefer to limit how many you keep at once. Also the space they take up is unlikely to be of a great impact itself unless you're running on a t...
Is it wise to delete post revisions and autosaves from database?
wordpress
I've enqueue'd jQuery from Google and it's displaying in the source code but no matter where I put my scripts they don't seem to work. Here is the site in question - http://www.deanelliott.me/handh/ Near the bottom of the page, there are a couple of testimonials, these should appear one at a time in a slideshow, but, a...
Upon first glance, both cycle.js and your javascript code need to be in the page AFTER jQuery is included. Right now, they are before so they both generate errors that <code> jQuery is not defined </code> . Make sure that jQuery is included first before you try to use jQuery. In the future, I would also strongly sugges...
Why is jQuery not working properly?
wordpress
I am attempting to make a custom search for BuddyPress groups. Here is my method: <code> public function search_groups($string){ global $wpdb; $results = $wpdb-&gt;get_results($wpdb-&gt;prepare( " SELECT * FROM {$wpdb-&gt;prefix}bp_groups WHERE `name` LIKE '%%s%' AND `description` LIKE '%%s%' AND `status` = 'public' OR...
I figured out a solution to my question. First of all, in my original query, I should have specified OR instead of AND for searching between group names and group descriptions. (It was skewing the results.) And I needed to double escape my '%'s in the LIKE statements. Here is the updated query which works correctly: <c...
How to use wildcards in $wpdb queries using $wpdb-> get_results & $wpdb-> prepare?
wordpress
I'm using plugin Woocommerce to do shop online. I have many categories for example <code> shoes </code> , <code> clothes </code> and so on. How can I display the products of specific category? I see such product loops of on the sample page , but I only want show the products of a specific category in my <code> index.ph...
You need to create a new loop for that. Here's the code I use for displaying products from a specific category on the home page: <code> &lt;ul class="products"&gt; &lt;?php $args = array( 'post_type' =&gt; 'product', 'posts_per_page' =&gt; 1, 'product_cat' =&gt; 'shoes', 'orderby' =&gt; 'rand' ); $loop = new WP_Query( ...
How to Display Product specific to a category with WooCommerce Plugin?
wordpress
I'm trying to build Wordpress based dictionary, basically it will have 26 pages (one for each letter): A B C ... X Y Z And every page will display all posts starting with given letter, so after opening the "A" page it should display something like: aback abacus abalone (...) azure I was thinking about custom post types...
Don't use post types, use taxonomy terms! On save, set the object terms in an A-Z taxonomy, using the first letter of the post title. Make sure to force upper or lowercase for consistency. Make sure to create terms for each letter of the alphabet, and a term for numbers and other non alphanumeric symbols. This should b...
Display all posts starting with given letter?
wordpress
Im looking for a way to add an alternating even/odd class directly to each image attachment when its outputted via my function below: <code> &lt;?php function nongallery_img_slide( $post_id = null ) { if ( $post_id == null ) return; $images = get_posts( array( 'numberposts' =&gt; -1, 'post_type' =&gt; 'attachment', 'po...
<code> wp_get_attachment_image() </code> has a fourth parameter for custom attributes. Use it: <code> if ( count( $images ) &gt; 0 ) { $i = 0; foreach ( $images as $image ) { echo wp_get_attachment_image( $image-&gt;ID, 'photogallery-img', FALSE, array ( 'class' =&gt; 'attachment-photogallery-img ' . ( ( $i++ % 2 === 0...
Possible to add "Even/Odd Classes" to image attachments via wp_get_attachment_image?
wordpress
Is there a plugin to collapse/expande subcategories in post edit screen? In other words I'm looking for analog of CMS Tree Page View plugin, but for categories.
Found it! Intuitive Category Checklist
Collapse subcategories in post edit screen
wordpress
Currently I'm developing a new theme for my business. This theme will have a header section with a drop down menu, a slideshow on the background and three featured images with a title, a description and an URL pointing to a page. Here is a screenshot of the website that I put together in Photoshop. So I want those feat...
Based on what you want, if it were me, I would enable featured images and excerpts on pages and then build a widget to feature a page. Then put a sidebar on your homepage and use those widgets to reorder and select which pages to show in which order. Then you're managing all content related to a page on that page and y...
How would you accomplish the following advanced settings page?
wordpress
I've searched google quite a bit and every site has the same filter but it doesn't seem to be working for me. Not sure if it's my setup or just old code. I'm trying this: <code> add_filter( 'avatar_defaults', 'newgravatar' ); function newgravatar ($avatar_defaults) { $myavatar = get_bloginfo('template_directory') . '/i...
I figured this out. The server I am working on doesn't have access to the outside. So, even though the image is in my template folder, the gravatar.com call in front of the image path was causing the error.
Replace default avatar
wordpress
When I activate my plugin (register_activation_hook), I add a new specific page and a corresponding item menu in the custom menu. No problem here. When I deactivate my plugin (register_deactivation_hook), I delete the specific page but I don't know how to delete the corresponding item menu from the custom menu ? Any id...
WordPress automatically handles that if you force delete the page instead of thrashing it. The following function takes a parameter to force delete -> <code> wp_delete_post( $postid, $force_delete ) </code>
Delete a specific item menu when I deactivate my plugin (resolved)
wordpress
I'm using Wordpress 3.4.2 for a private blog, i.e. one on which only I can post. Now, Wordpress prevents me from uploading certain file types (like C# source files). As far as I understand it, there's a white-list that defines what can be uploaded. Is there a plugin that can extend - or better, even disable - this whit...
Unfortunately, toscho's answer doesn't work - at least not in Wordpress 3.4 and above. The correct solution is the following: <code> # # For this, see: wp-includes/capabilities.php &gt; map_meta_cap() # function wpse_6533_map_unrestricted_upload_filter($caps, $cap) { if ($cap == 'unfiltered_upload') { $caps = array(); ...
Allow all file types for upload
wordpress
I've been reading a lot of questions here regarding about multiple blogs/sites in one Wordpress installation and I've added some of them to my favorites. But I still have the urge/nerve to post this question as I'm excited to have my first attempt in blogging. I will ask for your opinions and experiences on how to best...
No matter what you do: Avoid separate installations. You can use one installation to serve three or more single-site setups (just $_SERVER['HTTP_HOST'] </code> in your <code> wp-config.php </code> ) or one multi-site installation. But running three updates for the same software on one host doesn’t make sense. Just a wa...
Opinions whether to go multisite VS 3 separate WP installation
wordpress
Assuming I have a page with the URL <code> http://papermepress.com?page_id=2 </code> that I want to set as the default, what do I need to do so that when a user types in just <code> http://papermepress.com </code> they see that page? Is it a simple configuration option or do I need a plugin of some sort?
From your dashboard, visit <code> Settings &gt; Reading </code> and select and for the first option, <code> Front page displays </code> select <code> A static page (select below) </code> and then select that specific page (and then another page you create for your posts to show up on if you would like).
How do you set the default page in WordPress?
wordpress
The idea is simple. I have a drop-down menu generated with get_categories(). This outputs a list of categories in an unordered list, each in it's own li element. I'm getting the text values of those li elements when a user clicks them, and based on that i want to create a custom wp_query, that returns posts from that c...
That's because when calling a theme template directly you only have what's included/defined in the template file, not the whole WordPress environment. Some people attempt to fix this by adding an include of wp-header or load etc but this is incredibly damaging When doing AJAX requests, never call a file in the theme, i...
WP_Query class not found
wordpress
Is it possible to hard define a custom field value with a function? As in, no matter what WordPress will always set the value of 'some_meta' => 'this'
Instead of directly grabbing the meta, wrap it in a function, then you can provide a default, or, comment out the innards and just return "this"
Hard Define Custom Field Value
wordpress
I am developing a WordPress theme and would like to make use of a custom header on a the homepage (I'm using a custom page template). I would like this header to not include an image, but rather an <code> &lt;h1&gt; </code> and <code> &lt;h2&gt; </code> tag, and a link. So my question is the following - how do I go abo...
File: <code> functions.php </code> It's as easy as adding this to your functions.php file (of course having <code> $wpse67109 </code> set). <code> add_theme_support( 'custom-header', $wpse67109_defaults ); </code> File: <code> index.php </code> or any other template Simply don't add the whole <code> get_head_image() </...
Custom text-only header
wordpress
How to add audio files to wordpress blog that when someone clicks on a post Music began playing by itself.
Basic parts To get all audio files attached to a post use <code> get_children() </code> : <code> $audio_files = get_children( array ( 'post_parent' =&gt; get_the_ID(), 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', 'post_mime_type' =&gt; 'audio' ) ); </code> For the last attached file URL use <code> wp_...
How to add audio files to wordpress blog and making it auto play?
wordpress
Clients have been uploading huuuge images, then complaining that the server is running out of memory. Ofcourse one could bump the amount of memory, but this just introduces an arms race. What hooks can I add to impose a maximum image size ( dimensions, not filesize ) on files uploaded, e.g. No you can't upload that 8 M...
Basically you just retrieve the info via <code> getimagesize() </code> , a basic PHP function, a then handle your errors with notes. The plugin A basic plugin as a starting point: <code> &lt;?php /** Plugin Name: (#67107) »kaiser« Restrict file upload via image dimensions */ function wpse67107_restrict_upload( $file ) ...
Impose a Maximum Limit on Image upload size
wordpress
When I reply to a comment in the WP backend in the "Comments" section (edit-comments.php) I can only post the reply as the logged in user. Is it possible to select a certain user like in the "Add new post" section (post-new.php) where I have a dropdown with all users that are allowed to write posts?
Yes, add an user-select field in the comment form: <code> add_action('comment_form_after_fields', function(){ // allow only users who can moderate comments to do this if(!current_user_can('moderate_comments')) return; $user = wp_get_current_user(); wp_dropdown_users(array( 'name' =&gt; 'alt_comment_user', 'selected' =&...
Post comment as different user than logged in
wordpress
I have created front-end login form that allows users to login from front-end. However, when trying to access Admin section (dashboard), WP's default login form is displayed and user authorization is required. <code> $user_arr = array( 'user_login' =&gt; $u_name, 'user_password' =&gt; $u_pass, 'remember' =&gt; $u_remem...
OK, I've got it! According to wp codex, second parameter of wp_signon() function refers to whether to use auth cookie or not. So if you use <code> wp_signon( $user_arr, false ); </code> ...re-auth will not be required.
Front-end login problem: requires re-authorization when accessing dashboard
wordpress
i have a custom post which has a meta tag that needs to be using a file upload (for video files). I am wondering, what is the correct way of adding an Upload button that points to the wordpress media uploader and set the url of the selected uploaded file to the text field that caused that associates the upload button. ...
See this skeleton for use the media Uplaoder; is also use in your custom markup, like Meta Box. A hint, check, that you only use the scripts on the page, where you active your Meta Box. Otherwise is it often a problem on the default pages and the uploader. Now a attempt to clear the important parts to include the uploa...
Properly add an upload media button in a meta box field
wordpress
USER01 is not showing in Author drop down list while editing a Page if he's in the my custom ROLE "mycustomrole". If I change his role as an AUTHOR, and add the very same custom and non custom capacities, he's shown in the list. I created this role programatically, as shown below. Is there something particular to add i...
the answer is provided here: stackexchange-url ("Users with custom roles not showing in post author select box") I tested and it works: <code> to add a level_1 cap to your role. It's PITA, considering how user levels have been deprecated so long ago, but there you go </code>
One author not showing in Author drop down list while editing page
wordpress
I'm using the plugin "Formidable" to easily manage and create forms. I have set a custom post type, and created an extra post_meta. I can use meta('test'); within the loop to show my meta value on the posts single page. Everytime someone creates an entry by submitting the form thats on the single post page i want the v...
The following is a crude example, it can be improved to ensure you're dealing with integers etc and also shortened overall for brevity but this should get you started. <code> add_filter('frm_after_create_entry', 'after_entry_created', 30, 2); function after_entry_created($entry_id, $form_id){ global $post; if($form_id ...
update_post_meta after form is submited
wordpress
I have created a custom plugin that pulls video and images out of a post and puts them into a nicely formatted set of galleries. The only problem is that the plugin doesn't allow me to put a video or image before the more tag without creating a mini gallery. Is there a name or way to adjust my plugin to make it only re...
I think you can use the <code> get_extended( $post ) </code> function; that returns an array with different parts of the content. See this example which works inside the Loop: <code> $content_arr = get_extended( get_the_content() ); var_dump( $content_arr ); echo $content_arr['main']; //Display the part before the more...
Modify the_content after the more tag
wordpress
I have two sites in my multisite setup - <code> domain.tld </code> (site A) and <code> domain.tld/lifestyle </code> (site B). This is my first multisite attempt. I've made a widget that creates a custom post type " <code> latest-news </code> " with <code> WP_Query </code> and I call the widget via <code> dynamic_sideba...
Relevant: http://core.trac.wordpress.org/ticket/12002 <code> /blog/ </code> is added to prevent permalink clashes on the root site of a multisite install. For now you're going to have to resort to using the network admin and manually wading through the options table modifying it each time you regenerate rewrite rules. ...
Multisite custom post type's single page 404
wordpress
I have a gallery page wherein there are multiple individual galleries/sub-pages. I handle this function by using- <code> &lt;?php if( is_page( 39 ) ) { echo do_shortcode('[nggallery id=1]'); } else { } ?&gt; </code> I'm wondering, is there a way to include page specific content in that? For example, if that code is use...
You can do that via <code> echo </code> , just place it on a new line inside the if conditionals braces <code> { </code> and <code> } </code> e.g. <code> if(this statement is true) { // &lt;- do everything between here /* stuff that happens if the statement is true */ } // &lt;-- and here else { // stuff that happens i...
include content within conditional statement?
wordpress
I know that media are an attachment post type that are children to a post, but how are galleries stored in WordPress?
This completely depends on how your gallery shortcode looks like. If you replaced it with something custom, then you'll have to take a look at the plugin (or the theme). The default gallery shortcode gets it from a query: <code> $query_args = array( 'post_status' =&gt; 'inherit' ,'post_type' =&gt; 'attachment' ,'post_m...
Where does the gallery shortcode gets its attachments from?
wordpress
I set up wordpress newly and add next previous pagination in home page using following code <code> next_posts_link('Older Entries »', 0); previous_posts_link('« Newer Entries', 0); </code> Pagination URL work correct. when click previous link it go to http:www.mydomain.com/blog/page/2/ URL but content not load. IT show...
It's not clear why you're using query_posts or get_posts at all, WordPress does the main query for you before loading the template. If you simply want to change posts_per_page to something other than your site-wide settings, use pre_get_posts.
Wordpress pagination URL posts not load
wordpress
At first I had my <code> setcookie() </code> as: <code> $school = "Some Value"; setcookie("default_school", $school, time()+3600); var_dump($_COOKIE); </code> That didn't work, so I did some searching, and found that I probably just needed to set a path, so I changed it to: <code> $school = "Some Value"; setcookie("def...
If you’re doing this via a theme, add this line to your functions.php file: <code> function set_user_cookie() { $school = "Some Value"; setcookie('default_school', $school, time()+3600); } add_action( 'init', 'set_user_cookie'); </code> To display information add this line <code> echo $_COOKIE['default_school']; </code...
Issues with set cookie
wordpress
For link post formats to appear in my archive.php I'm using the following code: <code> &lt;a href="&lt;?php echo wp_trim_words( get_the_content(), 100 ); ?&gt;"&gt; &lt;?php the_content(); ?&gt; &lt;/a&gt; </code> Of course, this creates a validation error due to a <code> &lt;p&gt; </code> being inside an <code> &lt;a&...
You can temporarily remove the filter that adds paragraph tags: <code> // remove the filter remove_filter( 'the_content', 'wpautop' ); // output content the_content(); // add the filter again add_filter( 'the_content', 'wpautop' ); </code>
Post Format Link Validation Error
wordpress
I'm building a portfolio WordPress. It only displays image thumbnails, with a video element that call the fancybox. In the <code> &lt;a&gt; </code> tags, the attributes have the information for the fancybox to load the content. The <code> "href=" </code> is the url of the video to show, the <code> "title=" </code> is t...
This is how i got it working: <code> 'titleFormat' : function(title, currentArray, currentIndex, currentOpts) { return '&lt;span id="fancybox-title-over"&gt;' + jQuery(currentArray[currentIndex]).html() + '&lt;/span&gt;'; } </code>
Pass WP post content to a jQuery plugin (Fancybox)
wordpress
Ok, my question is a bit complex so I will try and give a general explanation and then go into details afterward. I am running WordPress 3.4.2 and I am using WCK Post Type Creator and WCK Custom Fields Creator to create my custom post type and custom fields. I am trying to query posts from the custom post type 'busines...
Normally you would just specify a meta_value, e.g.: <code> $args = array( 'post_type' =&gt; 'business', 'meta_query' =&gt; array( array( 'key' =&gt; 'specials', 'value' =&gt; 'these are not the specials you are looking for - Obi Wan Kenobi' ) ) ); </code> However because your post meta is actually a data structure, a s...
Can I query custom meta data through WP_Query
wordpress
I'm using the following function (can't remember where I found it, but I think it was written by pippin so thanks to him) to test for a shortcode. <code> function has_shortcode($shortcode = '') { $post_to_check = get_post( get_the_ID() ); // false because we have to search through the post content first $found = false;...
Try this instead: <code> function has_shortcode($shortcode = '') { global $post; // false because we have to search through the post content first $found = false; // if no short code was provided, return false if ( !$shortcode ) { return $found; } if ( is_object( $post ) &amp;&amp; stripos( $post-&gt;post_content, '[' ...
Testing for a shortcode using a function. 404 page throwing PHP Notice
wordpress
Working on a theme template and trying to make the menu responsive, so that it will change from a horizontal layout into a block format at a certain screen resolution. I have tried one tutorial which I couldn't get to work, lack of experience on my behalf but also a little unsure how to implement in to WordPress as the...
Looking at that tutorial, you need to match up the jQuery selector with the menu markup. You can see in this line <code> navigation: $('#nav ul'), </code> that the jQuery expects your menu to be in a <code> &lt;ul&gt; </code> inside a parent element with the id <code> nav </code> . Luckily, that's really easy to do. Ju...
Responsive dropdown menu with smaller screen sizes
wordpress
I'm getting a well known error from the question title. The problem is, website is running on a shared server and I don't have access to php.ini file. I've set `php_value memory_limit' inside .htaccess to higher value. I've set <code> WP_MEMORY_LIMIT </code> inside wp_config.php to higher value. <code> phpinfo() </code...
You can simply create a text file and call it php.ini . Make sure the file has the text encoding "Unicode no BOM", as that will work best for both linux and windows. Use an FTP client to make a new file on the server and that will generate a file with the correct permissions and text encoding. Put just this line in it:...
Allowed memory size exhausted. WordPress side solution
wordpress
I hava a big form and when a user fill it I need to create a new user in Wordpress from there. Its posible to create and user from the frontend and add some custom information? Thanks
Yes, yes you can. The relevant functions to do this are: <code> wp_create_user </code> Creates a user given a user/pass/email <code> wp_insert_user </code> Creates or updates a user given user/pass/email <code> add_user_meta </code> Adds User Meta ( same as Post Meta/Custom fields but for users rather than posts ) You'...
Register new user in the frontend
wordpress
Before I update a Wordpress install (including the theme and various plugins) I wanted to ensure no one is logged in and editing the site. Is there a way to do this? Thanks!
Because of the stateless nature of webpages, you can't do this without a high margin of error. You can install a plugin to log last visits for logged in users, but that will not tell you if they're editing posts or if they loaded a page then went to lunch or shut down their computer. Instead, use maintenance mode and a...
Check if any users are logged in before running update
wordpress
How do I turn off the WP Super Cache &amp; W3 Total Cache functionality programmatically? For instance, I neither want to make it use the cache on some requests nor cache the output of the request, do they support that using filters? I couldn't find anything useful in their documentation.
Easiest way to do this was to define a constant programmatically: <code> // Tell WP Super Cache &amp; W3 Total Cache to not cache WPReadable requests define( 'DONOTCACHEPAGE', true ); </code>
Disable WordPress cache programmatically on a request
wordpress
Does anyone know if it is possible to use this editor as my WordPress editor and not the default. If so, how?
Yes, It is possible ... there is a good article on DigWP - which points out one warning that MarkDown is not reversible (ie articles written in Markdown get saved in Markdown so if you ever turn off MarkDown, then you're left with goo on your screen). There is a MarkitUp plugin on the WordPress.org ... While the projec...
Use MarkItUp as editor and not the default
wordpress
So I have a search function that just fetch custom posts and return them as a list. <code> function search() { // post query args $args = array( 'post_type' =&gt; 'post_type', 'posts_per_page' =&gt; -1, 'post_status' =&gt; 'publish' ); // markup $markup = '&lt;ul&gt;'; //the loop $loop = new WP_Query($args); while ($lo...
If it's not timing out, you're likely running out of memory.
WP_Query() and get_posts() can't handle over a thousand posts?
wordpress
I'm creating a page that is pulling info from Vimeo using oEmbed. Everything works fine but the multiple calls to vimeo are causing page load issues (obviously). I was wondering if it would be possible to make the same oEmbed call when the post is being created/saved, then populating various post meta variables with th...
Yes, most definitely. Take this skeleton code below as a base for a function that would do what you want, and place it in your functions.php: <code> function your_vimeo_meta_function ($post_id) { // some verifications first if ( $post_id == null || empty($_POST) ) return; if ( !isset( $_POST['post_type'] ) || $_POST['p...
running function during post save and adding variable to post meta
wordpress
How can I exclude authors by ID from this: <code> &lt;?php //displays all users with their avatar and their posts (titles) $blogusers = get_users_of_blog(); if ($blogusers) { foreach ($blogusers as $bloguser) { echo '&lt;div class="content-slider-body"&gt;'; $user = get_userdata($bloguser-&gt;user_id); echo '&lt;div cl...
Where <code> $that_user_your_filtering_out </code> is the user/author ID you wan't to filter out, make this modification to your loop <code> foreach ($blogusers as $bloguser) { // modification starts here if($bloguser-&gt;user_id == $that_user_your_filtering_out){ continue; } // modification ends here echo '&lt;div cla...
Exclude Author by ID
wordpress
I want to let the users search posts by categories. So I use wp_dropdown_categories to build a drop-donw list with all categories. Trouble is I want to allow them to set this to "ALL CATEGORIES" as well. So how can I add another entry in the drop-down list? Thanks,
Should be easy to do (check the codex: wp dropdown categories ) <code> &lt;h2&gt;&lt;?php _e('Categories:'); ?&gt;&lt;/h2&gt; &lt;div&gt; &lt;?php wp_dropdown_categories('show_option_all=ALL CATEGORIES&amp;show_count=1&amp;hierarchical=1'); ?&gt; &lt;/div&gt; </code> p.s if you want to wrap with translation this is the...
How can I add an "ALL CATEGORIES" entry in wp_dropdown_categories?
wordpress
In the user profile in Dashboard I have a section 'Contact info' containing email, URL, aim, yahoo, jabber. I would like to build a widget and output that user info within the widget. What function should I use to get just the contact info of a user?
It sounds like you're after the get_userdata() function. As a basic example, you could retrieve a users email like this: <code> &lt;?php if ( $user_id ) { $user = get_userdata($user_id); echo 'Users Email is: ' . $user-&gt;user_email; } ?&gt; </code>
How to get user contact info
wordpress
can someone help me to create a thumbnail gallery in Wordpress using jquery masonry which looks similar to this ? I am not sure what the best approach is. Especially regarding the different thumbnail sizes. When and how to assign them? I get the part where I set a few different thumbnail sizes, but how do I decide whic...
Make a grid setup, with your guttering, and setup JQMasonry to appyl itself to everything in that grid. Then add image sizes for the sizes of tiles you want using add_image_size in <code> functions.php </code> . You will need to regenerate any existing image thumbnails after this has been done. Then finally display you...
Various thumbnail sizes for Wordpress/jquery masonry gallery
wordpress
Some posts are requested through Ajax. <code> &lt;?php // Filename: ajax-posts.php require_once "wp-load.php"; echo my_get_post($_GET["id"]); ?&gt; </code> How can I make theese Ajax requests cacheable by W3 Total Cache?
Short answer: You can't. Getting W3 Total Cache to talk to a non-WP call in manor listed above isn't (easily) possible. I completely agree with @allenericr comments. The Transients API is very straight forward and quite simple to implement. In addition, @allenericr, comment on using admin-ajax.php is also spot on. It's...
How to cache custom pages using W3 Total Cache?
wordpress
I have a custom login page at http://netballscoop.com/log-in/ When you fill the username and password it redirects you to the previous page you were on perfectly. When you click Log Out it redirects you to the same page. So this all works well. If you leave the username/password blank or have an error it will lead you ...
You can filter the <code> login_redirect </code> function like so, adapt according to your needs. <code> add_filter('login_redirect', 'redirect_previous_page', 10, 1); function redirect_previous_page( $redirect_to ){ global $user; $request = $_SERVER["HTTP_REFERER"]; if ( in_array( $user-&gt;roles[0], array( 'administr...
Login redirect to previous page
wordpress
I am no programmer but I can usually work stuff like this out when I read the code. I have a theme called Infinity which only supports 1 menu. I know how to do CSS etc but I can't find how I would a second menu. In fact it doesn't have to be a custom menu but just the pages. Can anyone tell me how to do this? An excerp...
Adding custom menu position to your wordpress theme is fairly simple. This is usually done this way: 1. Announcing the desired menu positions (in function.php): <code> add_action( 'init', 'register_my_menus' ); function register_my_menus() { register_nav_menus( array( 'first-menu' =&gt; __( 'First Menu' ), 'second-menu...
Add a Second Menu to a theme that only support 1 menu
wordpress
How can I add a custom field to an array? To complicate matters, custom field is on the Author's page, not on a regular post. It's added via Advanced Custom Fields. Typically, that field value would be called with <code> &lt;?php the_field(author_status); ?&gt; </code> . Here's the full code I'm working with right now....
This was added to the area with repeatable content: <code> &lt;?php the_author_meta( 'author_status', $user-&gt;ID ); ?&gt; </code> Replace author_status with the name of your AUTHOR CUSTOM FIELD. Solution is from here: http://codex.wordpress.org/Function_Reference/the_author_meta
Adding custom field to an array
wordpress
I am building a segmented search (by post type) with the ability to filter to a specific post type and realized pages were not publicly queryable. What I know I can do is the following: <code> function fix_page_query() { if ( post_type_exists( 'page' ) ) { global $wp_post_types; $wp_post_types['page']-&gt;publicly_quer...
Just to close this one out - you can set Pages to be <code> publicly_queryable </code> using the function provided above.
Is there a reason why Pages are not publicly_queryable?
wordpress
I need to disable the admin bar for subscribing user ( not the admin). I found these code snippets here on SE. stackexchange-url ("Best Option") stackexchange-url ("Another Option") However I don't know what file to edit or where to put the code exactly. I have experience with PHP, HTML, etc. Just not so much with the ...
This would go in your theme's <code> functions.php </code> file. This is a small tweak, but things to remember are that: If you ever change your theme, you'll need to remember to copy this over to the new theme It'd be better to put these types of "system tweaks" into your own plugin, which you can read about here Go w...
Disabling the Admin Bar | Where does code go?
wordpress
If so, how should the query URL be formatted? I've tried: <code> post_type=cat1&amp;post_type=cat2 </code> <code> post_type=cat1,cat2 </code> <code> post_type=cat1+cat2 </code> This bug report says you could use <code> post_type[]=cat1&amp;post_type[]=cat2 </code> if not for the fact that "all request parameters are co...
You could use <code> add_feed() </code> and create new feeds … for each post type combination a separate feed. That's not what I would call flexible, so I recommend to create an endpoint. The following code creates an endpoint for the root of a WordPress installation. After refreshing the permalinks you get a regular f...
Is it possible to request several post types from a feed?
wordpress
How can I highlight comments that have been made by registered users of my blog?
Comments that are left by registered users are given the class "byuser" - so you can create a style in your theme's stylesheet to point out these comments. Something like: <code> .commentlist li.byuser { background:#FF0000; } </code> That would make the background of users' comments red (insert a more appropriate color...
Highlight comments made by registered users of the site
wordpress
I like to output and style in a shortcode, but the content that is get is the content of a page, so it's style like that <code> &lt;p&gt;2012-12-12&lt;/p&gt; &lt;p&gt;2012-6-23&lt;/p&gt; &lt;p&gt;2012-7-3&lt;/p&gt; </code> i like to be able to have ONLY the value date in a array to be able to output it in a unorder lis...
Firstly, you need to remove the paragraph tags that were added by the <code> wp_autop </code> filter. There's another answer that covers this pretty well: stackexchange-url ("Is there an uw-wp_autop function?") I'm going to change the function a little for our purposes (based on the markup example you gave): <code> fun...
How to split text text text into array
wordpress
I have setup a great voting system on my website, but since I want to sort the top rated posts by week, month and alltime...I now need to able able to keep track of when a vote has been cast. Could anybody help/nudge me in the right direction? I followed this tutorial: http://wp.tutsplus.com/tutorials/how-to-create-a-s...
The following lines of code both store the IP address and time of vote, <code> // $ip holds $_SERVER['REMOTE_ADDR'] $voted_IP[$ip] = time(); // Save IP and increase votes count update_post_meta($post_id, "voted_IP", $voted_IP); </code> The time a vote is cast is already being stored for you in the <code> post_meta </co...
How to keep track of when a vote is cast?
wordpress
Edited to rewrite my question I'll try to be as clear as possible, as I need to get this resolved quickly. I disabled WordPress' cron, and added a real cron job on my server to call wp-cron.php every day. The function i'm calling is not working, however. Code execution seems to stop at <code> get_posts </code> , same t...
Whenever you do get_posts or WP_Query or anything like that, it's important to remember that the code is actually getting all of the Posts at once, and loading them from the database into memory. If you run out of memory, then your process will simply die with an error. Attempting to get very large numbers of posts at ...
get_posts inside cron
wordpress
I'm unsuccesfully trying to use the add_{$meta_type}_metadata. This filter is called inside add_metadata function (wp-includes/meta.php:31 in Wordpress 3.4.2). In particular I wanna hook "add_post_metadata" filter among others. My target is to execute custom code to add,update,get custom meta, so I don't break wordpres...
Ok I've found the solution... I have had to call add_filter outside my plugin class, because of Wordpress hooks priority. With the actual code, I call add_filter after the 'init' event, that's probably too late. If I move this line of code: <code> add_filter('add_post_metadata',array(&amp;$this,'filter_negozi_add_metad...
Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
wordpress
I have a specific need to import many post with featured images into a custom post type. The issue is, I need this to be a script because it runs off of another system that collects all the data. I currently have the custom post types setup and I have the data to be displayed in the custom post type using custom templa...
It appears it is possible and not too difficult. Here is the code snippet I used. I also added in some checks to prevent duplicated images in the media manager but that code snippet is unique to my needs (I just used a meta key to each attachment and checked for duplicate keys before adding new attachments.) I hope thi...
Is it possible to add posts and images (auto resize) for custom post types with a script?
wordpress
I have this code in my header.php and it is working: <code> &lt;div id="news"&gt; &lt;?php query_posts('category_name=news'); ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div class="new"&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt; &lt;?php the_post_thumbnail('thumbnail'); ?&gt; &lt;/a&gt; &lt;a ...
<code> the_views() </code> is not a built in function of WordPress. In fact, WordPress does not, by default, log the number of views of posts. There are probably several plug-ins that exist which add this functionality. The only one I have ever used (and its one I've never had any problems with) is WP-Postviews http://...
How to show the number of each post has been read in a while loop?
wordpress
I am trying to develop a dashboard widget that counts posts or post types by month. I am really not sure how to go about doing this. I know how to create a dashboard widget and all that with post counts, post type counts. I even have a custom one that lists the most recent post types i have. But I have yet to create on...
Just Went over your code and it looks fine but you are missing the code blocks for your foreach loops so: <code> add_action('wp_dashboard_setup', 'dashboard_test'); function dashboard_test() { global $wp_meta_boxes; wp_add_dashboard_widget('month_dashboard', 'Reports Submitted for the Year', 'custom_test'); } function ...
Grabbing how many posts by month for a dashboard widget
wordpress
I have a post-meta field for Neighborhood. I want to setup a url like: url.com/neighborhood/NEIGHBORHOOD-NAME I know this would typically be handled by a CPT or custom taxonomy but it has to be done with a post-meta field in this case. I also want this to use a custom template, not one of the standard templates. I can ...
There's the core function <code> add_*/get_query_arg() </code> that you can use to append stuff to the query and retrieve it. So simply add a link somewhere, that points to your custom post types single.php template <code> single-{$custom_post_type}.php </code> Then append the query arg which would be <code> ?wpse_meta...
How can I setup custom templates for a meta-data query
wordpress
I'm a newbie in WordPress and I've just created a new custom-post type called arts. Is there a way I can create a custom page to display the 'art's custom type? The custom-post type has thumbnails which I'll be displaying on the post and 'arts'are a bit more different form other posts. Any help offered will be highly r...
I f you set the argument <code> has_archive </code> in <code> register_post_type() </code> to <code> TRUE </code> you get an archive automatically. Depending on your slug it will be available on <code> /arts/ </code> probably. To customize the look of that page use a template <code> archive-{post_type}.php </code> .
Page for custom post type
wordpress
I am building a WP site using the Panoramica theme by CPOThemes , and so far most of it is working really well. However, not all translations work as they should (or at least not as I expect them to). Specifically, I can't figure out why the header "Archives" on the main page isn't translated. The site can be found her...
To get <code> 'Archives' </code> translated in your text domain you have to load a theme translation <code> .mo </code> file. The file in <code> /wp-content/languages/sv_SE.po </code> will not be used for that. Create a directory <code> languages </code> in your theme. Add the translations for the theme to that directo...
How do I troubleshoot translation issues?
wordpress
I had two instances of jquery in my code and everything used to work. I decided to get rid of wordpress stock jquery by deregistering it through functions.php file. But now not a single jquery animation/script I've works! I've jquery hardcoded in my header though: <code> &lt;script src="http://ajax.googleapis.com/ajax/...
Include jQuery the correct way with Function Reference/wp enqueue script « WordPress Codex ; that method includes jQuery in "no conflict" mode with toher libraries and other javascript http://docs.jquery.com/Using_jQuery_with_Other_Libraries , and if you use Dev tools or Firebug, you will find two JS errors TypeError: ...
jquery stopped working after deregistering wordpress stock version
wordpress
On the home page I a have 2 lines of code I would like to run in JavaScript. Where should I put these two lines of code. Does WP have a specific way to do this. Or should I just pick the last .js file that loads and add it there?
yes, WordPress has a function for loading javascript files: http://codex.wordpress.org/Function_Reference/wp_enqueue_script the last argument takes either true or false to load in the footer
Script to run at completion of Page Loading
wordpress
I am writing some PHP which allows users of my site to submit a form and query posts by their post_meta. Everything works fine except for one thing, I used Advanced Custom Fields to create the post_meta and ACF saves meta values as a serialized array. I need to keep the data in this format so ACF can pre-fill the custo...
I found a way to build a custom query that goes through the checkboxes the user selected and then adds an array for that value to the query dynamically. That way it checks to see if each value selected is in the serialized array, and then moves onto the next one. Runs a lot smoother than what I was doing before. <code>...
meta_query with array as value
wordpress
Is it possible to repeat this loop after four posts? (post 5 = post 1 css, post 6 = post 2 css, etc..) <code> &lt;?php if (have_posts()): while (have_posts()) : the_post(); $count++; if ($count == 1) : ?&gt; &lt;div&gt;Styled post 1&lt;/div&gt; &lt;?php elseif ($count == 2) : ?&gt; &lt;div&gt;Styled post 2&lt;/div&gt; ...
Assuming that you're only using the counter to decide what style to use, the easiest way to achieve what you want would be to reset the $count variable once it gets to 4. <code> &lt;?php elseif ($count == 4) : ?&gt; &lt;div&gt;Styled post 4&lt;/div&gt; &lt;?php $count = 0; ?&gt; &lt;?php else : ?&gt; </code>
How to repeat a loop after 4 posts
wordpress
Ok, I've seen solutions which go halfway to sorting out this problem, but nothing definitive, and nothing that 100% solves my problem. Scenario: In HTML mode, I add some javascript to a post I'm editing. I switch to Visual, then back to HTML, and the tag and all of its content are gone. How do I stop this from happenin...
Adding JS to the content is very, very bad practice , and it's just asking to be hacked . Add it via a shortcode, or if you really must, use a post meta/custom fields to store the js and display it after the content in your template using <code> echo get_post_meta($post-&gt;ID,'post_javascript',true ); </code>
Stop Wordpress removing tags when switching from HTML to Visual (TinyMCE)
wordpress
I'm trying to add my custom Wordpress table (similar to the links table) into the "New Post" view of a custom post type. I hope that makes sense.
Ok. So the only way that I found to do this is wrap the WordPress table in a custom meta box. This is not ideal, because I would like to see the table span the entire container, but it works.
Wordpress Admin Tables in Post View
wordpress
I'm trying to create a custom permalink structure. I'd like to have a custom page which displays each post's image attachments, using the following structure: www.mysite.com/hello-world/images If anyone visited this URL, it would serve up a page of images that are attached to hello-world. It's kind of like having a sub...
You could achieve that by adding a rewrite endpoint via <code> add_rewrite_endpoint </code> . This post from a WordPress developer has a good explanation of how they work.
Create a permalink for a post's attachments
wordpress
I have included a code which fetches any post under my category=featured. And that shows-up on the top of my content (*whenever we have any breaking news to show*)on blog-page. The problem is, The image that I can afford to show on single-post is of 750px width, whereas I have enough space to show 1100px image on the p...
You can show featured images at multiple sizes easily enough, by specifying the size of image when you make the call, but if you want them to be different you can use the code in this plugin: http://wordpress.org/extend/plugins/multiple-featured-images/ Here's a tutorial: http://lifeonlars.com/wordpress/how-to-add-mult...
Big Image on Featured Post, Normal on Single Post
wordpress
I have created a custom post type called 'course' which has 7 posts each being an individual training course. I've also tagged them with individual custom taxonomies 'course_codes' eg. h001, h002, h003, etc. These correlate to the individual courses provided by a training centre. I have several training centers that ha...
The <code> term </code> parameter should actually be <code> terms </code> , even when providing just one term: <code> $args = array( 'post_type' =&gt; 'course', 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'course_codes', 'field' =&gt; 'slug', 'terms' =&gt; 'h001' )), 'post_status' =&gt; 'publish' ); </code>
Tax query not producing any results
wordpress
I'm using Woocommerce and its atributes (custom taxonomies). I have some pages which I query this way: http://example.com/?tax1=term1&amp;tax2=term2 This query gives me the posts from taxonomy 1 and taxonomy 2 that matches term1 and term2. I'd like to insert some text on these pages. Any way to accomplish this? Thank y...
Ok, but I was afraid it's not really a good solution. Works, though. First, I rewrote the query in order to get pretty permalinks: <code> /*Añadido: Reescribir URL query: "?pa_dispositivo=nombre&amp;pa_marca=nombre"*/ function custom_rewrite( $wp_rewrite ) { $feed_rules = array( 'tipo/(.+)/marca/(.+)' =&gt; 'index.php?...
Any way to insert text on page from a query results?
wordpress
This seems like a fairly simple question, and I'm sure I'm overlooking something, but how does one display forum statistics (registered users, posts, etc.)? I see there is a template in the theme compatibility folder called <code> page-forum-statistics.php </code> which seems to display some of this info but I'd like i...
It seems BBPress got a function called <code> bbp_get_statistics() </code> read source . You can throw an array of <code> $args = array(); </code> in it. You also have a filter to modify the output: <code> apply_filters( 'bbp_get_statistics', $statistics, $args ); </code> Disclaimer: I'm no BBPress expert - I haven't e...
How to display BBpress statistics?
wordpress
E.g. if I use this code inside functions.php <code> add_image_size( 'featured-extra-image', 600, 300, true ); </code> and the uploaded image is only 550px width, it does not resize it to 600x300 px but only to 550x300 px. How to force WP to resize it to my custom size, even it is bigger than original uploaded image?
When you add the image to the post Select "Full Size" Click "Edit Image" Click the "Scale" button Manually edit the dimensions Save all changes Check to see if "Full Size" has your new dimensions Click "Use as featured image"
Resizing to bigger proportions as original not working
wordpress
Next in my quest to extend WordPress is altering how WordPress uses the the <code> $sentence </code> variable in <code> posts_search </code> to include an additional string, when the <code> $sentence </code> variable meets a certain criteria. The specific usecase here is that when someone types in something like <code>...
Gladly I've written two plugins for that yesterday: Filter/Core That's what a search query part looks like inside the <code> posts_search </code> filter: <code> ' AND (((wp_XX_posts.post_title LIKE '%test%') OR (wp_XX_posts.post_content LIKE '%test%'))) ' </code> where <code> wp_XX_ </code> is just the <code> $wpdb-&gt...
Extending search query with additional $sentence value
wordpress
I have the following function that lists all Child-Pages of a page. <code> function show_subpages() { global $post; $subpages = wp_list_pages( array( 'echo' =&gt;0, 'title_li' =&gt;'', 'depth' =&gt;2, 'link_before' =&gt; '&amp;mdash; ', 'child_of' =&gt; ( $post-&gt;post_parent == 0 ? $post-&gt;ID : $post-&gt;post_paren...
<code> function show_subpages() { global $post; $subpages = wp_list_pages( array( 'echo' =&gt;0, 'title_li' =&gt;'', 'depth' =&gt;2, 'link_before' =&gt; '&amp;mdash; ', 'child_of' =&gt; ( $post-&gt;post_parent == 0 ? $post-&gt;ID : $post-&gt;post_parent), 'exclude' =&gt; ( $post-&gt;post_parent == 0 ? '' : $post-&gt;ID...
List all-childpages on parent-page AND list child-pages on childpage itself but not the current one?
wordpress
My website allows uses to post posts of a custom post type ("place"). I would like to display the same "Categories" meta box seen in WordPress dashboard when you add or edit a post on frontend: This is because the "Categories" meta box or hierarichical checkboxes is simply the best way to view and edit the categories a...
Try <code> wp_terms_checklist() </code> / <code> wp_category_checklist </code> . It will output a list of checkboxes named <code> post_category </code> . You might need to include the source file too, because it's defined within administration files. Or use a custom walker: <code> class MyCategoryWalker extends Walker_...
How to Make a Categories Meta Box with Hierarchical Checkboxes on Frontend?
wordpress
Hi I am trying to use jQuery sortable to sort items in a widget on the admin side. However I am having trouble getting any data in the JS file when I do <code> alert(order) </code> . Any idea what might be wrong here? in the php file: <code> /* Plugin Name: Test widget */ add_Action('widgets_init', 'boj_widgetexample_r...
The script you are loading will apply the sortable to all elements with the <code> .mywidget-list </code> class just after the document has loaded. Once you drop your widget inside a sidebar, a new <code> .mywidget-list </code> element is created trough $.ajax, which cannot have your sortable function attached to it, b...
Using AJAX in a Widget to Sort items
wordpress
I want to wrap a link around a featured image (only if the custom meta box has been filled in), the link will come from a custom meta box. Here's my image code: <code> the_post_thumbnail('screenshot'); </code> Here's my code for displaying the link using text: <code> &lt;?php //Only if $urllink is filled in, display th...
Unless there's some part of your problem I don't grasp, what's wrong with a simple mash-up of the two given snippets? <code> &lt;?php global $post; $urlbox = get_url_desc_box(); $post_thumb = get_the_post_thumbnail( $post-&gt;ID, 'screenshot' ); if( !empty( $urlbox[0] ) &amp;&amp; !empty( $post_thumb ) ) { echo sprintf...
Wrap Featured Image in a Link
wordpress
I want to create a drop down list that will list all the posts in the category. I want the drop down list to appear on every post. So for example if I view a post that belongs to category Apples it should list all posts in category Apples
Hey @Ruriko ... its a 3 step action. get the current category ID get the posts for this specific category get the posts into a select menu Please note that this code would use the first category id altough you might assign several categories to the same post. . <code> &lt;?php // FIRST CATEGORY NAME $category = get_the...
Create dropdown list post
wordpress
I'm trying to migrate my wordpress from a subfolde to the root. I've already done it from localhost to the subfolder with the same method <code> update_option('siteurl','http://example.com/blog'); update_option('home','http://example.com/blog'); </code> But this time it does not look to work... It says "Call to undefin...
It sounds like your opening <code> &lt;?php </code> tag is abutting your first call to update_option. If it isn't directly adjacent to it, perhaps the whitespace between the two is unrecognized for one reason or another (this can happen from copying and pasting from some sources). Have your functions.php file start off...
Wordpress Migration error phpupdate_option is not a function
wordpress
I need to create an "Empty Trash" button inside my plugin. How would I do it using PHP code?
You can use <code> wp_delete_post </code> . To get all posts with the "trash" status: <code> $trash = get_posts('post_status=trash&amp;numberposts=-1'); </code> Then: <code> foreach($trash as $post) wp_delete_post($post-&gt;ID, $bypass_trash = true); </code>
How do I programatically empty trash?
wordpress
When a file with the <code> .xml </code> extension has been uploaded on my blog (via the Add Media uploader) I would like to automatically replace some attributes. For example, if I upload a file with this content: <code> &lt;content creator="foo"&gt;&lt;/content&gt; </code> I would like that Wordpress modifies it auto...
You can do this using the <code> wp_handle_upload </code> hook: http://adambrown.info/p/wp_hooks/hook/wp_handle_upload?version=3.4&amp;file=wp-admin/includes/file.php Create a function and add it to this hook so it runs last, it will be passed an array. The array contains the location of the newly uploaded file: <code>...
Post processing of uploaded file
wordpress
Fixed the problem by adding <code> if ( 'email' == $type || 'email2' == $type ) { </code> to the top of the snippet below and changing the first elseif to a if statment I have created a WordPress register form on the homepage of my WordPress but I am having a little problem with verifying the email address match. This ...
Firstly, this isn't an error, it's a warning. If it's causing a page crash rather than a logic bug, thats because you're printing your error log to the screen, not logging it to a log file as you should be doing. Turning off display errors should fix this. This still leaves you with the warning, and those are still bad...
Null value given when confirming email's
wordpress
I have a nice plugin that is called Select WP-Table Reloaded and that works well, except the contents don't show up in a useful manner. The page the table is embedded shows up in a search, but not the specific term. Is there any way to remedy this? This is the page the table is embedded in: http://henschelhausbooks.com...
Suggested here by JLeuse . It seems the contents within WP Table Reloaded is indeed separated from the post, which means the default Wordpress search function won't be able to fetch it...
Search within table?
wordpress
I want to use <code> $query = new WP_Query( 'post__in' =&gt; array( 2, 5, 12, 14, 20 ) ) ); </code> to retrieve posts by ID, I do and the result ordered by publish date but I want to retrieve in same of IDs in this example in this order: 2, 5, 12, 14, 20
In WordPress 3.5, you'll be able to do this with the 'orderby' parameter set to 'post__in'. Until then, this question is basically identical to another one, which I wrote an answer for already: stackexchange-url ("Orderby = none not working")
how to retrieve WP_Query without ordering by date
wordpress
When query a post, I need not only the post but also the post_meta. But seems the post query and meta query can not be done together. With WP_Query, I first get the posts, then, I need to do <code> get_post_meta(get_the_ID(),'key',true) </code> Is this the way WP works? Or, is there a way to query both in one hit?
When you do a query WordPress already gets the post_meta. Even though you are calling <code> get_post_meta() </code> It is not performing another query. It is retrieving the value from the post meta cache. Now if you don't need the post meta you can set a flag that will eliminate the additional MySql query. To do this ...
How to get post meta value and post in one query?
wordpress
I'm using the below code to highlight the page name/gallery shown when the corresponding link is clicked on. My challenge is that regardless of what link I click, only the very first link( <code> page_id=24 </code> /Haagen-Dazs) is highlighted. Any ideas what's causing the issue? Thanks. live site CSS <code> .active { ...
Use a WP Nav menu or the built in APIs instead. They all have current cat/active/parent highlighting on posts/pages, all out of the box
trouble with page_id & highlighting current page
wordpress
I have been trying for two weeks to add a edit custom meta field to the admin edit comment form. I managed to show the field in the form, but it can't get it to update. I would also like to add this field to the registration form and profile. this is what I have so far <code> add_action( 'comment_post', 'save_comment_m...
The get_comment_ID function was not working. So use following code in location_meta_call function <code> function location_meta_call(){ $location = get_comment_meta($_GET["c"],'location', true); } add_filter('comment_save_pre','location_save'); function location_save($comment_content){ global $wpdb; $id = $_POST['comme...
ask and edit an extra comment field
wordpress
My blog is mainly composed of posts describing hiking. Actually, since I just moved from a Wordpress.com blog to a self-hosted Wordpress blog, every hike is inserted in a simple post. However, every hike has certain parameters (e.g.: ascent, length, difficulty, ...) I'd like to save in the database in form of attribute...
I'd suggest looking at a couple of plugins to help out since you're just starting out. Advanced Custom Fields will allow you to add the metadata to your current posts. Once you've added the custom fields, set it to display your Field box only on posts in the "hiking" category, for instance. You'll need to edit your the...
Add custom attributes to a post
wordpress
i want to add a link to the first post of every WP blog that i have. For example this simple function adds the link to every post. <code> function add_link($link){ $link .= '&lt;a href="http://site.com"&gt;Link&lt;/a&gt;'; return $link; } add_filter('the_content','add_link'); </code> so basically instead of the link sh...
Just remove the filter when it is called the first time: <code> function add_link($link) { // this will guarantee the filter will not be called again. remove_filter( current_filter(), __FUNCTION__ ); return $link . '&lt;a href="http://site.com"&gt;Link&lt;/a&gt;'; } </code>
how to place a link on the first post only using a plugin
wordpress
I know this this is covered as individual topics but What I am looking for is a single function that stops <code> &lt;p&gt; </code> tags from being wrapped around via the Wordpress editor to shortcodes and images and also removes empty <code> &lt;p&gt; </code> tages, for example: remove <code> &lt;p&gt; </code> tags th...
1. Filtering the content Here's a one-function content filter to meet the above four requirements: <code> add_filter( 'the_content', 'strip_some_paragraphs', 20 ); function strip_some_paragraphs( $content ) { $content = preg_replace( '/&lt;p&gt;(([\s]*)|[\s]*(&lt;img[^&gt;]*&gt;|\[[^\]]*\])[\s]*)&lt;\/p&gt;/', '$3', $c...
How to to stop html editor from addig tags to shortcodes, images, etc
wordpress
I have to use WordPress as some meta templating system and include some <code> JSP </code> snipptes which will be evaluated later with Tomcat after rendering the page statically. But naturally the <code> JSP </code> Code could not be interpreted by the php parser. This results in plain text strings mixed with the inter...
You can, but WP doesn't offer you the possibility to do it in a nice way, so you have to use output buffering. Something like: <code> // before template is included add_action('template_redirect', function(){ // you can do some checks here // perhaps you need this only a certain page? if(!is_home()) return; // capture ...
Hook into the rendering of a WordPress Template
wordpress
Okay, here's the deal. I am working with a child theme and I want a custom post type. What I did Added the following code the <code> functions.php </code> of the parent theme. <code> add_action( 'init', 'create_fb_foto_post_type' ); function create_fb_foto_post_type() { register_post_type('fotos', array( 'labels' =&gt;...
You need to flush and regenerate your permalinks everytime you modify/add/remove custom post types or taxonomies. Going to the permalinks page and saving should be enough ( Also your custom post type code should be in a plugin, not the theme, else the user is stuck using that theme forever )
Custom post types and child theme
wordpress
My main posts are news items (category "news"). Therefore, I used global URI writing in the following format: <code> /year/month/post-name </code> I also have posts that contain photo albums (category "photo") but I want these to have another URI structure, namely: <code> /category/post-name </code> in which category i...
I solved it myself (with you guys' help): It was easy as anything: <code> 'rewrite' =&gt; array( 'slug' =&gt; 'videos', 'with_front' =&gt; false ), </code>
Custom post types with their own permalink structure
wordpress
I'm trying to remove the post content from the buddypress activity stream and would like to replace the content/body with a custom field that I've added in. Any ideas where I should be looking? I've been looking around for a while and cant seem to figure it out. I am using WordPress 3.4.1 &amp; Buddypress 1.5.6
You should state which versions of WP and BP you're using. This should change the content part of what is recorded. You can put it in your theme's functions.php <code> add_filter( 'bp_blogs_activity_new_post_content', 'record_post_activity_content', 1, 3 ); function record_post_activity_content($activity_content, $post...
Remove post content from buddypress activity
wordpress