question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
On the WordPress Edit Image Screen, I'd like to add a label to show the current compression level and byte file size of the image. Any ideas how to tap into this screen and echo this data? The current settings show: Date URL File name File type Dimensions I'd like to ad File Size File Compression (echo the current jpeg...
You can try to use the <code> attachment_submitbox_misc_actions </code> filter to add more info to the box. Here is an example for the filesize part: <code> add_action( 'attachment_submitbox_misc_actions', 'custom_fileinfo_wpse_98608' ); function custom_fileinfo_wpse_98608(){ global $post; $meta = wp_get_attachment_met...
Add Additional File Info (jpeg compression & file size) settings to Edit Images Screen
wordpress
I have created some custom widgets based on the standard WP text widget by extending the WP_Widget class. I would very much like to force the title of the widget on to a new line in the sidebar summary area of the admin section. I was thinking of using a line break html tag so that the title doesn't become truncated or...
You can try this custom CSS code to enable multiple title lines for the widgets in the backend: <code> function custom_css_wpse_98587() { echo "&lt;style&gt; .widget-top{height:auto !important;} .widget-title h4, .widget-title span.in-widget-title{ white-space:normal; } &lt;/style&gt;"; } add_action('admin_head-widgets...
Forcing the title of a text widget on to a new line in the admin area
wordpress
I have trouble in getting post in a custom post type category. I have code below but it doesnt work well. It still get posts in another category. <code> &lt;?php $query= null; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args=array( 'post_type' =&gt; get_post_type(), 'post_status' =&gt; 'publish', '...
As far as I know there is no such parameter as <code> post_type_cat </code> , you want to use either <code> cat </code> or if querying posts in a custom taxonomy you would use a taxonomy query. Category query example; <code> $query = new WP_Query( 'cat=2,6,17,38' ); </code> or <code> $query = new WP_Query( 'category_na...
Get Posts in a Custom Post Type category
wordpress
I have WordPress v3.5.1 and using a theme from WPZoom. I added an SEO plugin called WordPress SEO which in turn added 4 more columns to my Posts Admin table which caused the columns to squish together making it very hard to see all the posts now. I have tried to change the CSS in the admin CSS but that does not help at...
You can control columns in most admin panels by clicking <code> Screen Options </code> at upper right of the screen and (un)checking them as you want. This is however saved individually for user and to get rid of column for all users would involve writing code to hook into internals and unregister it.
Fix Admin Dashboard Posts tab
wordpress
I have a big list of prohibited words on the DB. The problem Im running to is that no comment is getting through. They are all getting sent to spam. I was looking at comment.php and found the functions that are handling this. I dont wanna modify the core functions but to write my own. I tried something like <code> add_...
<code> wp_blacklist_check </code> is an action - it does not return results and does not influence logic. Hook you want is <code> pre_comment_approved </code> filter that gets two arguments - <code> $approved </code> ( <code> 1 </code> , <code> 0 </code> or <code> spam </code> ) and <code> $commentdata </code> with com...
wp_allow_comments checking for blacklisted words effectively
wordpress
I've written my first simple WP widget-- it all works fine, but I'd like to dress it up a bit, and add an image / logo in the widget display code. How do I package the widget (which is just a single PHP file) with the image, and where will the image be stored in the WP site (so I can create the img tag link correctly)?...
It sounds like you'll need the <code> plugins_url() </code> function which generates the URL for the plugins directory and can handle any alternate configuration (such as if you moved it to the <code> /mu-plugins/ </code> directory, a personal favorite of mine). The Codex documentation is good, but here's a quick examp...
including image assets in widget
wordpress
I created a custom user meat value and want to add a new key/value to this array. But somehow I can't get it to work correctly, I always get a new array in side the array so that I always have e new dimension. But I want to keep just one dimension and add the new key/value pair. I know this is nothing complicated but s...
You need to pass <code> get_user_meta </code> a third parameter to prevent it from returning an array. That is where the mistake is, not with the add/update functions. <code> $invoice_meta = get_user_meta( $_GET['id'], 'invoices', true); </code> You will need to clean up any data already in the database or the existing...
Get custom_user meta value and add entry
wordpress
I followed stackexchange-url ("this link") and created my own custom query with pagination, But I don't really understand how the offset work. This pagination does not work well, and I'm getting zero value for offset: <code> function spiciest(){ global $wpdb, $paged, $max_num_pages; $paged = (get_query_var('paged')) ? ...
The problem here is the LIMIT, it'll just count the first page and not the entire query. I had solved it by providing a secondary SQL query for counting the max pages. thanks for my friends for this tip. here's the complete code. function.php <code> function spiciest(){ global $wpdb, $paged, $max_num_pages; $paged = (g...
How does offset works on pagination? (get_results)
wordpress
I have been currently building a custom widget in WordPress based on the text widget as a starting point. It seems that within the <code> function __construct </code> part of the widget, the class name is a hard coded string. I would like to make this hard coded string more dynamic by calling a separate file which has ...
Your problem is due to your trying to <code> include </code> a file over the http protocol. That kind of <code> include </code> is disabled on your server-- hence the message saying pretty much just that. Use <code> get_template_directory </code> instead, which will give you a filesystem path. If that does not solve it...
Creating a dynamic class name in my custom widget
wordpress
That was a very dense title. I have a custom post type "event" which has a Date/Time picker field "event_date" thanks to the Advanced Custom Fields plugin. This Date/Time picker saves a UNIX timestamp to the database. I'm trying to use WP_Query to get all events that are today or in the future. This is the code that I ...
Try an array of arrays in your meta query. <code> $args = Array( 'post_type' =&gt; 'event', 'posts_per_page' =&gt; -1, 'meta_key' =&gt; 'event_date', 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'ASC', 'meta_query' =&gt; array( array( 'key' =&gt; 'event_date', 'compare' =&gt; '&gt;=', 'value' =&gt; intval(strtotime(...
Filtering a WP_Query meta_query by numeric values isn't working
wordpress
I removed automatic formatting in my WP site by adding this to functions.php: <code> remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); </code> Now I need to add it back into one section only. On page.php, I want to replace the_content with wpautop formatted content. I replaced this: ...
Please try this <code> $c = get_the_content(); </code> instead of: <code> $c = the_content(); </code> since <code> the_content() </code> will echo the content instead of returning it. Or try this <code> &lt;section class="post-content clearfix" itemprop="articleBody"&gt; &lt;?php add_filter( 'the_content', 'wpautop' );...
wpautop on section
wordpress
I have the following function that returns the tags of the current post: <code> &lt;?php the_tags( '&lt;ul&gt; &lt;li&gt;', '&lt;/ li&gt; &lt;li&gt;', '&lt;/ li&gt; &lt;/ ul&gt;' ); ?&gt; </code> Example: Is there any way to split the result into 2 columns? Would return something like this: Any hint is welcome. Thank y...
Use <code> get_the_tags </code> instead of <code> the_tags </code> to grab an array of tags, and <code> array_chunk </code> to split it. You will then need to build a loop to display the tags. <code> $tags = get_the_tags(); if (!empty($tags)) { $tags = array_chunk($tags,ceil(count($tags)/2),true); foreach($tags as $v) ...
Split function "the_tags" in 2 columns
wordpress
Case Study: I need people pay me when they come to register on my site. Most of the page should be only available for logged in user. Paypal will be my payment options. Question? I need to know how can i communicate with paypal after making the payment that a user did the payment or not?
Best way is to handle this with user roles. A user can register but not read. After paying with paypal, the role will be updated (e.g. from reader to subscriber). The update can be done through PayPals IPN. I made this for one of my clients. You will be paid by your customer. I will be paid by you. You got the plugin. ...
Payment on Registration?
wordpress
I use PHP-Markdown plugin in WordPress. In order to show the formula beautifully, I add some code to use MathJax . Like this: <code> &lt;script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"&gt;&lt;/script&gt; &lt;script type="text/x-mathjax-config"&gt; MathJa...
I'm not sure this is a real answer, but have you tried PHP-markdown-extra (by the very same Michel Fortin)? At least for me (using Mark Jaquith's markdown-on-save plugin ) your example is not a problem. But Markdown-extra is not perfect either and I've seen some other quirks with respect to emphasis, e.g. Let $(y_n)_{n...
How to deal with the confliction between PHP-Markdown and MathJax?
wordpress
I have a custom post type called "Newsitems" that I have registered two custom taxonomies for: "newsitem types" and "news item tags" I want these two taxonomies' terms to appear almost like the typical post meta info would for categories and tags, but at the client's request they need to function separately than the de...
<code> get_the_terms() </code> you are using is returning array of items, which cannot be simply echoed to page. You should try using higher level <code> get_the_term_list() </code> function, which returns string of concatenated results and can be echoed.
Custom Post Types Archives and Single Pages not showing custom taxonomy data
wordpress
I am trying to show a sub-menu of child-pages only on level 2 pages (who have a parent) and if they have children. I am using the code below (made from several snippets I found), it works fine on level 1 (not showing anything as meant to be), works fine on level 2: if there are child pages they are shown in the sub-men...
Use ancestors : <code> $ancestors = array_reverse( get_post_ancestors( $post-&gt;ID ) ); // reverse ancestors to make it more intuitive if ( isset( $ancestors[0] ) ) { if ( isset( $ancestors[1] ) ) { // 3rd tier $parent_id = $post-&gt;post_parent; } else { // 2nd tier $parent_id = $post-&gt;ID; } $args = array( 'depth'...
Test if page is child and has children, if so echo child pages also on grandchild pages
wordpress
I have a multisite with two subsites (sub-domain setup) both sites have the same theme, same plugins but the first one is in Hebrew and the Second in English. On certain templates (not all) in the English site "the_content()" doesn't work (it works just fine on the Hebrew site). This is on a custom-post-type, but not a...
Check for any filters that only <code> return </code> if certain conditions are met. I had an issue once where almost all my pages' content areas were blank. I found the problem was in a snippet of code that looked like this: <code> add_filter( 'the_content', 'this_will_blank_pages' ); function this_will_blank_pages( $...
the_content not working on one of two Multisite sites
wordpress
I am using the simple <code> add_filter </code> function to output the content. <code> add_filter('the_content', 'my_name'); function my_name( $content ){ // code return $content; } </code> When I activate the plug-in output of the function <code> my_name </code> is shown in all pages. How can I restrict the output to ...
Add this code and replace <code> yourpagename </code> with the your page slug on which u want this filter to execute <code> function my_name( $content ) { global $post; if ( $post-&gt;post_name == 'yourpagename' ) { return $content; } } add_filter( 'the_content', 'my_name' ); </code>
WordPress plugin installation
wordpress
Ive placed a link in the sidebar, however its not showing up at all! Any ideas? The link is the blackburn text in the post. http://pcdconsultancy.co.uk/ thanks Kirsty
I'm guessing that text is an excerpt - and so any mark-up will be stripped out.
Links In Sidebar not displaying
wordpress
I've spent a few days researching working with WP static pages - as separate from posts. Although I've found useful guidance, I can't seem to find any good tutorials or worked examples that show me how to work with pages using a modified WordPress Loop that will enable me to filter on specific page criteria and extract...
@userabuser's input provides a useful discussion on using Custom Post Types to solve the customisation need. However, this still left unanswered my main question: Can I interrogate a pages template type or custom meta data within a loop? I wanted to use wordpress static pages with a custom template as an alternative to...
Interrogate a page within a loop to check template type or custom meta data (Pages vs Posts)
wordpress
I would like to share a document with about 140 users after password authentication and I want to avoid to create manually all the 140 accounts. Is it possible to create them quickly? UPDATE : usernames to add are stored into a text file. The question is focused on the batch users creation because I will create a passw...
This is a small code I wrote to batch create generic users <code> &lt;?php $lock = true; //true = disabled (locked) if(!$lock) { // if not locked require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' ); $last_registered_user = $wpdb-&gt;get_row("SELECT ID FROM $wpdb-&gt;users ORDER BY ID DESC LIMIT 1"); $new_id = $l...
Batch users creation
wordpress
I'm trying to fetch content about the current post into the header.php of my theme (to dynamically insert Facebook OpenGraph Metadata). Since I'm on a single post page, shouldn't it be able to run functions like <code> the_content() </code> or <code> wp_get_attachment_thumb_url() </code> ? <code> &lt;?php if (is_single...
Consider this snippet here to accomplish your task. If you add it to your <code> functions.php </code> file, the Open Graph tags will be populated automatically as part of the <code> wp_head </code> action.
Why don't some template tags work when querying information on single.php?
wordpress
I have two widgets, one shows News while the other shows everything except News (We'll call the second one Blog ). The blog portion is currently working correctly. The News posts are either categorized as <code> In the News </code> OR have the custom post meta <code> in-the-news </code> , set to 1. It's important to no...
Is it possible to do a custom query and convert it to a standard WP_Query object? Yes. You can do something like... <code> $post_ids = $wpdb-&gt;get_col("SELECT ID FROM {$wpdb-&gt;posts} WHERE ...."); $posts_qry = new WP_Query(array('post__in'=&gt; $posts_ids,'orderby' =&gt; 'post__in')); </code> The second query will ...
Custom query with category exclusion and post-meta "whitelist"
wordpress
I've been trying to commission a freelancer to make me a custom website and hit a roadblock when I said I wanted a parent theme. The freelancer strongly preferred to make a child theme based on his self-made, free go-to theme that he updated frequently. Justin Tadlock did a great writeup on Frameworks? Parent, child, a...
While I agree with Justin Tadlock on a lot of things, I strongly disagree with him on this. The reason parent/child themes exist is that there's a lot of common functionality used across websites. Instead of re-inventing the wheel every time, it's better to build from a solid base that has been tested by hundreds of de...
What are the best practices for maintaining and deploying several parent themes?
wordpress
This code counts the number of words in an excerpt and adds it to the excerpt meta box in the post edit screen: http://snippi.com/s/sn3hk5p However, something about this code is preventing the editing of permalinks in the post edit screen and I am unable to identify the problem. Any ideas?
I put the script in a external file <code> // Excerpt word count function excerpt_count_js(){ wp_enqueue_script( 'excerpt-word-count', plugins_url( 'excerpt_word_count.js', __FILE__ ), array( 'jquery' ), false, true ); } </code> And modified the script a bit <code> jQuery(document).ready( function($){ $("#postexcerpt ....
Word Count Function Preventing Permalink Editing
wordpress
I am attempting to exclude all sticky posts from my front page in twenty twelve theme. I have attempted the following. I am making all changes to the child theme. To remove the following code from content.php <code> &lt;?php if ( is_sticky() &amp;&amp; is_home() &amp;&amp; ! is_paged() ) : ?&gt; &lt;div class="featured...
Don't use <code> query_posts </code> . Use a filter on <code> pre_get_posts </code> . <code> function no_front_sticky_wpse_98680($qry) { if (is_front_page()) { $qry-&gt;set('post__not_in',get_option( 'sticky_posts' )); } } add_action('pre_get_posts','no_front_sticky_wpse_98680'); </code> By running <code> query_posts <...
Exclude all sticky posts front page twenty twelve
wordpress
I have this query to show custom post type "property", and it works really well but the "orderby" statement, that is completely ignored... <code> $args = array( 'post_type' =&gt; CUSTOM_POST_TYPE1, 'post_status' =&gt; 'publish', 'meta_key' =&gt; 'estado', 'meta_value' =&gt; 'Activa', 'orderby'=&gt; 'modified', 'order' ...
There is an <code> ORDER BY </code> clause in that query that should not have been generated by those arguments. Plus, it doesn't look like a WordPress query-- note the capitalization. WordPress tends to use all uppercase for SQL functions and operators. I suspect that there is a filter on <code> posts_orderby </code> ...
WP_Query order custom post type with certain meta key value by post modified date
wordpress
I am new to ajax and I've been struggling for 3 days now on how to solve my problem. I am trying to fetch the value of the date input (input type="date" in html)and pass (post method) it to ajax so that it can be processed. My goal is to be able to update a certain post meta value of multiple posts filtered via post da...
If you want to post the value as soon as user has entered the date and click somewhere else, this might help you: <code> jQuery('#your-name').on('blur', function(){ var date_Value = this.value; var ajaxdata = { action: 'process_date', date_value: date_Value }; jQuery.post(ajaxurl, ajaxdata, function(res){ /* whatever y...
Fetch the input type date value via ajax
wordpress
I am creating a mobile version for a site. For that I am using WPTouch not WPTouch-Pro. Now I want to add a form in my page. For desktop version I used template to add form. But in mobile version it's not working. When I exit mobile version form is present in my page. I saw some post which suggest to add child theme an...
As WPTouch uses its own theme, we can't hardcode certain functionality inside the regular theme, neither in a page/post template nor <code> functions.php </code> . So, a stackexchange-url ("custom plugin") is needed and the desired output made out of a Shortcode . Also, make sure WPTouch <code> Restricted Mode </code> ...
Adding a template in WPTouch
wordpress
I regularly use Advanced Custom Fields to create awesome backend interfaces for my clients (as I'm sure a lot of us do…). ACF includes an Options add-on that creates one or multiple global options pages that one can pull data from anywhere. I use the Options page to, for example, let the client select the 5 posts to be...
This function will clear WP Super Cache upon saving of ACF Options page. Enjoy! <code> &lt;?php /* Additional Function to prune the Cache if $post_id is '0' or 'options' */ function f711_clear_custom_cache($post_id) { // just execute if the $post_id has either of these Values. Skip on Autosave if ( ( $post_id == 0 || $...
Empty Super Cache programmatically (with ACF action)
wordpress
I have a page with the following markup in the site theme footer: <code> &lt;div id="modalpopup"&gt;&lt;div id="inside"&gt;&lt;/div&gt;&lt;/div&gt; </code> I have a variable in the WP db I can retrieve via <code> GetOption() </code> which I would like to stuff into that <code> div#inside </code> on page load via jQuery...
You would still do this with AJAX, except that instead of firing on some event like a 'click', or 'hover', or <code> submit </code> , you would fire the Javascript function on <code> jQuery(document).ready </code> instead. That will execute immediately on page load. It doesn't let you execute the code before the page l...
Pull GetOption() variable into jQuery dynamically created html
wordpress
I have the following code for showing images using the shortcode image but the shortcode is [image name=logo] to load an image from /uploads/ directory called logo.png; changing the name I can load different images just like dog.png bullet.png etc. writting after name= the name file. So my question is how to make the f...
Change <code> 'name' =&gt; '', </code> to <code> 'name' =&gt; 'logo', </code> Then when there is no name field passed to the shortcode, it will default to logo, which will load logo.png.
shortcode for logo image
wordpress
I'm a beginner writing website and use WordPress and I'm writing plugin that involves profile page (not avatar because this field that I implemented, user can upload image, anything, i.e. Picture of my friends) and I added field upload that browse file from directory and save them to database using WordPress' <code> wp...
Output during saving You can not print something during the data is saved. If you use <code> die( var_dump( $your_var ) ); </code> it will print the values, but also stops the script. The reason is, first the data will be parsed. Then you will be redirected back to <code> profile.php </code> . So everything you print w...
Upload image to wordpress
wordpress
I have 2 user roles. "photographer" and "subscriber" I have set my author.php like this <code> &lt;?php get_header(); $thisauthor = get_userdata(intval($author)); $author_user = $wp_query-&gt;get_queried_object(); ?&gt; &lt;div id="main"&gt; &lt;?php if (user_can($author_user, 'photographer')) { get_template_part( 'aut...
To change all author URLs one would normally change the author base , however, since you want multiple author bases, we'll have to do things a bit differently. There are two parts to this - The first part is getting WordPress to recognize incoming requests for your custom author pages and route them properly. To do thi...
Author Profile URL
wordpress
This plugin has an unique way of registering styles and scripts so I have no idea on how to stop it from loading on all my pages. After a quick search to see where wp_enqueue_style&amp;script is I came up with this. <code> Line 263: wp_enqueue_style($h); Line 277: wp_enqueue_style('thickbox'); Line 143: add_action('wp_...
If it is called by shortcode, then the shortcodes are fired before the page loads (which is why you never echo in a shortcode) - you could cut out the existing call to the enqueue, and add it to the shortcode function at the top. If not, then as RRikesh suggests, you could wrap the relevant code in a <code> if(is_page(...
Stop a plugins js and css from loading on all pages and show up only where it is called
wordpress
I'm having a very peculiar issue with Wordpress right now that I can't understand, and hopefully someone here will have experience with it to help solve it. I'm trying to iterate through the array returned by <code> get_the_tags() </code> using a standard loop (not foreach), but whenever I attempt to access it through ...
get_the_tags() returns an array but the indexes do not start at 0 because they are the term ids.
get_the_tags() not iterating through for/while loop, but will with foreach
wordpress
<code> //wraps the permalink around each thumbnail add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 ); function my_post_image_html( $html, $post_id, $post_image_id ) { $html = '&lt;a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '"&gt;' . $html ...
That is not the way functions work. You can't tack part of an <code> if/else </code> query onto the end of a function... at least that kinda looks like what you are doing. Or maybe you're are trying to us an <code> else </code> without the <code> if </code> ... Anyway, the syntax is badly broken. Here is a cleaned up v...
Exclude single page from function
wordpress
Why do we need to enqueue styles on a hook, why not just enqueue them straight in like this? <code> wp_enqueue_style( $handle, $src); </code> the codex page gives an example of using a hook but doesn't explain why (or if) it's important.
There is code that needs to run, thing that need to be setup, before you enqueue. If you enqueue too early those prerequisites will not be filled and you will see ... Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scri...
Why enqueue styles on hook
wordpress
I'm running wpmu on heroku using a postgres extension. It works great, but I have a plugin that needs to get the userId based on the e-mail-adress. This is how it does it: <code> $sql = 'SELECT id FROM ' . $wpdb-&gt;users . ' WHERE user_email='' . addslashes($from) . "' LIMIT 1;"; $user_ID = $wpdb-&gt;get_var($sql); </...
The plugin should use the API, not some made-up SQL. <code> addslashes() </code> is not safe enough anyway. <code> $user = get_user_by( 'email', 'user@example.com' ); echo $user-&gt;ID; </code> Besides that, the user tables are almost the same, there are just some tighter restrictions for user names in multi-site, beca...
Is the wordpress user-model changed in wpmu?
wordpress
I have an issue pertaining specifically to the situation in which permalinks are set to be based only on publication date. My permalink structure is as follows: /%year%%monthnum%%day%/ When I try to preview a post, I get 404. The issue does not come up when I add other URL tags to the structure, like post ID or post na...
I will sum up my findings for future use by others: When using permalink structure that uses only date tags, Wordpress is unable to identify a unique post because there may be more posts in any given day. For this reason Wordpress treats URLs with date based tags only as date archive pages. Given the permalink structur...
Post preview gives 404 when permalinks are purely date based
wordpress
Here is my loop code, i want to call different page templates for different pages . Please notice that this is a one-page-layout . <code> &lt;?php $args = array( 'post_type' =&gt; 'page' );?&gt; &lt;!-- get only pages --&gt; &lt;?php query_posts($args); ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;!-- lo...
Yes, there are a few improvements. Needlessly opening and closing PHP tags is a timewaster, makes it harder to read, and means more typing PHP Alt/short style syntax isn't going to play as nicely with the editor. Use {} instead, and your IDE may even help you type out the closing brace automagically. Query_posts, never...
Is there a way to make this kind of loop shorter and nicer?
wordpress
I'm a bit stuck with a WP_Query code. Here it is : <code> $args = array( 'post_type' =&gt; 'post', 'meta_query'=&gt; array( 'key' =&gt; 'karma', 'compare' =&gt; '&gt;=', 'value' =&gt; 0, 'type' =&gt; 'numeric'), 'posts_per_page' =&gt; 9, 'meta_key' =&gt; 'karma', 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'DESC', ...
A <code> meta_query </code> is an array of arrays. Look at the examples in the the Codex . <code> $args = array( 'post_type' =&gt; 'my_custom_post_type', 'meta_key' =&gt; 'age', 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'ASC', 'meta_query' =&gt; array( array( 'key' =&gt; 'age', 'value' =&gt; array(3, 4), 'compare...
WP_query : meta_key with custom rule for specific value
wordpress
I'm creating a small widget for wordpress 3.5 that allows you to upload images. The widget is loaded correctly by wordpress. When I add the widget to a sidebar upload button does not work. If I update the page of keeping my widget in the sidebar, button works and I can load and save the image correctly. To build the wi...
Check if this works for you: Put this code in <code> jQuery(document).ready( function(){ function media_upload( button_class) { var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; jQuery('body').on('click',button_class, function(e) { var button_id ='#'+jQuery(this).attr('id'); /* console....
Use Media upload in custom widget on wordpress 3.5
wordpress
I've built a widget to show pages from a certain category in a dropdown menu. The page that's selected will show up on the homepage. This all works, except the Advanced Custom Fields (ACF) are all showing the same image. I think it's to do with $instance... The code I'm using is: <code> &lt;div class="home-image-box"&g...
Try passing the post ID as the second parameter: <code> the_field('sub_title', $instance['post_id']); </code>
Using Advanced Custom Fields in a widget
wordpress
I want to add social share buttons to my posts, but I don’t want to put all that big bulk of code into all my content files. I want to create a function, and then add the function name to my template files, something like this: <code> function pietergoosen_sosiale_netwerk_deel_knoppies() { &lt;strong&gt;Deel die pos me...
There are a couple of problems with your code: You have to close the PHP context, if you want to output plain HTML: <code> function foo(){ ?&gt;&lt;strong&gt;&lt;?php } </code> Don’t repeat yourself. Always store repeating values in variables or functions. Writing <code> &lt;a href </code> more than once is a bug. Do n...
List repeating share links
wordpress
I have a homepage on which I want to display the latest post different from the other posts. I haven't used <code> post_class </code> and I am not sure how to. Would I be able to achieve what I want using <code> post_class </code> ?
You should be using <code> post_class </code> (and <code> body_class </code> for that matter) but you don't need it for this. Alter your Loop on your home page to conditionally format the first post. <code> $first = (!is_paged()) ? true : false; if (have_posts()) { while (have_posts()) { the_post(); if ($first) { // co...
Using post_class to style posts indivdually
wordpress
In my blog , I used the Day and name permalink structure for many days. Recently I came to know the SEO tips and made the permalink structure to Post name. So I migrated from: <code> http://nishachor.com/%year%/%monthnum%/%day%/%postname%/ </code> to: <code> http://nishachor.com/%postname%/ </code> It's very simple for...
You could use a redirect in your server/site configuration, for example a <code> RedirectMatch </code> in your .htaccess: <code> RedirectMatch permanent ^/\d\d\d\d/\d+/\d+/(.*) /$1 </code>
Permalink redirection from 'Day and name' to 'Post name'
wordpress
This is the statement of post submit:* <code> &lt;fieldset&gt; &lt;label for=MarketItem_cost&gt;&lt;?php echo __('Software Version', 'WpForest'); ?&gt;:&lt;/label&gt; &lt;p&gt;&lt;input type="text" size="50" class="do_input" name="soft" value="&lt;?php echo get_post_meta( $pid, 'WpForest_soft', true ); ?&gt;" /&gt; &lt...
Try using this: <code> // Get the 'WpForest_soft' custom field value. $text = get_post_meta( $post-&gt;ID, 'WpForest_soft', true ); // Print the value and surrounding markup only if the value tests true. if ( $text ) printf( '&lt;tr&gt;&lt;td class="attr-name"&gt;%s&lt;/td&gt;&lt;td class="attr-detail"&gt;%s&lt;/td&gt;...
Only display on sidebar if only got value inserted on post
wordpress
I am working on developing a theme which automatically creates a page on theme ativation. But the problem if when the theme is switched and activated again, it recreates the page. is it possible to put a check if page is already available/publish, don't create or perhaps delete the page on theme switching/deativating? ...
You are calling <code> get_page_by_title( $page_title ) </code> already. Use it! <code> if ( ! get_page_by_title( _x( 'Homepage Template', 'home page title', 'your_theme_textdomain' ) ) ) { // create the page } </code> Do not delete user content on theme deactivation. The user might have put much energy into that page,...
Remove specific published page when theme deactivated
wordpress
I'm creating a shortcode to display the list of users with a particular profile in WordPress. But I can not enable or display the pagination. I have 25 users on my site and would like to display 5 profile users per page and include the pagination. I added a new Role student, and multiple custom fields using Advanced Cu...
I realise that you say that you can't enable paging of users, but if it's a case of you don't know how, you can pass 'number' and 'offset' in the args array. In your example to get page 2 of your users, set 'number' as '5' and 'offset' as '5'. If using those variables is not suitable you can always use a for loop with ...
How to use/enable Pagination?
wordpress
How it possible to redirect all users, even administrators after login to specific page? And also redirect users after successful registration? Any simplest way? For example I want to redirect users after login, to the "Updates" page of my website. And after registration, to the "Home" page of website.
This code adapted from: stackexchange-url ("Registration Redirect") <code> add_filter( 'registration_redirect', 'ckc_registration_redirect' ); function ckc_registration_redirect() { return home_url(); } </code> This code adapted from: Login Redirect <code> add_filter( 'login_redirect', 'ckc_login_redirect' ); function ...
Redirect user after login/registration globally
wordpress
I have a site that needs two different tabs: 1. all author written content (Posts, comments, CTP) 2. all author followed content (categories, taxonomies, other users content) For the first all I could come up with was using unoion on wp_comments and wp_posts filtered by author sorted by date Have no idea how to do the ...
Found out the solution for #1. using WP_Query I can specify multiple post_type and an author ID. which gives all author written data...
How can I get all author written content?
wordpress
I add my custom taxonomy column with this code: <code> function manage_my_category_columns($columns) { if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'products' ) return $columns; $columns['image_column'] = 'Image'; return $columns; } add_filter('manage_edit-products_columns','manage_my_category_columns'); func...
What is happening is that: the page <code> /wp-admin/edit-tags.php </code> uses <code> $_GET['taxonomy'] </code> and <code> /wp-admin/admin-ajax.php </code> , fired when we create a new term, uses <code> $_POST['taxonomy'] </code> To solve it, use <code> $_REQUEST </code> in <code> manage_my_category_columns() </code> ...
Showing custom taxonomy column in taxonomy category listings immediately after create category
wordpress
I need to create a special form for my website where users cand specify a series of data including some textfields, combo boxes and sliders (from 0 to 100). Also I need this form to be qTranslate compatible, for my website is multilingual. What would be the easiest, cheapest approach for this? I tried the lite version ...
What would be the easiest, cheapest approach for this? Simple, create one form per language. In <code> functions.php </code> or, preferably, as a stackexchange-url ("custom plugin"): <code> add_shortcode( 'my-lingo-form', 'shortcode_wpse_98360'); function shortcode_wpse_98360() { $lingo = your_language_detection_method...
Creating a custom multilingual form
wordpress
I'm customizing a WordPress theme for my school, and I'm a bit annoyed by the fact that the current page in the nav menu is not indicated. For example: You can clearly see that I'm hovering over a page in the nav menu, and that the page I'm hovering over is highlighted, as expected. However, the page that I'm currently...
The Navigation Menus system is adding a lot of classes, including matching current page (rather intelligently, it will even try to detect custom URLs, that were input explicitly). The simplest class to make use of is <code> current-menu-item </code> , but there are quite a few more dealing with parents/ancestors and mo...
How to highlight the current page in the nav menu?
wordpress
I've been looking around for this for a while but haven't found anything as of yet. I have a custom post type - "books" and this post type has a custom meta field of "availability". I would like to have a column for the post type that you can click on the availability link and it would change the custom meta value from...
There are some issues with the solution in the linked answer. But it is a good starting point for it. Basically you have to change only the method <code> ajax_change_status() </code> . This method changes the post status, but you want to change a post meta. In short, this is the final class with some fixings <code> /**...
Change Post Meta via AJAX from the posts list table
wordpress
Okay, so I want to do something, and after searching on Google I couldn't find any answers. Maybe you guys can help. basically, I want to assign every post with a little bit of unique identification information. Every post would be tagged white, gray, or black. I don't want to use categories or tags because I want to d...
There are two mechanisms in WordPress that would fit your use case: custom taxonomies and post metadata. Since you have already determined that you want something close to mechanics to categories/tags (which are built-in taxonomies) it seems like custom taxonomy is a right fit for your use case. See <code> register_tax...
Not sure how I would go about doing this in WP.. related to custom tags
wordpress
Does anyone know how to make this page template to only show knowledgebase post types? I've tried various different ways but with no luck <code> &lt;?php $cat_args = array( 'taxonomy' =&gt; 'knowledgebase_category', 'orderby' =&gt; 'slug', 'order' =&gt; 'ASC', 'hierarchical' =&gt; true, 'parent' =&gt; 0, 'child_of' =&g...
Had to do a complete rewrite in the end also using a complete different post type approach
template page to show custom a post types only
wordpress
So when WooCommerce updated to version 2 they replaced the fancybox lightbox scripts with prettyphoto. I would like to use this on all my wordpress site's pages, not just the product pages, but the scripts are only loaded on a product page. I have a jQuery script to add the relevant css class to my image links but I ne...
Try adding this to your theme's function.php. It worked for me, hope it helps. <code> // PRETTY PHOTO // add_action( 'wp_enqueue_scripts', 'lightbox' ); function lightbox() { global $woocommerce; $suffix = defined( 'SCRIPT_DEBUG' ) &amp;&amp; SCRIPT_DEBUG ? '' : '.min'; { wp_enqueue_script( 'prettyPhoto', $woocommerce-...
Include WooCommerce 2's prettyphoto scripts on all site pages
wordpress
How can I add pre-defined options to the "add new" custom field dropdown? Here's two examples of automatically adding and showing new custom fields: WordPress: Adding Default Custom Fields on New Posts Auto create custom field That's close to what I want to do; my goal is to add pre-defined options to the "add new" cus...
You cannot do that with pure PHP, because the fields are fetched from existing fields, and there is no hook. But you can use JavaScript, check if the post type supports custom fields and the field does not exist already – and insert it: <code> &lt;?php # -*- coding: utf-8 -*- /* Plugin Name: Extend custom fields */ add...
Programatically add options to "add new" custom field dropdown
wordpress
This code displays a list of child categories of the parent category while a user is on a child category or single post. The styling around this list is displaying even when a list isn't being generated. Take a look here where you'll see an empty black box - I've colored it black simply to make it stick out. Not releva...
Check that you actually have categories before creating the list, and move the lines that echo the <code> &lt;ul&gt; </code> inside the conditional. <code> $categories = get_the_category(); if (!empty($categories)) { foreach($categories as $category){ $parent = $category-&gt;parent; if($parent != 0){ echo '&lt;ul style...
Insert Into Sub-child Menu
wordpress
I need to restrict access to certain frontend pages, based on a user_meta field. All works fine, except when the user is already logged in but with the wrong credentials. In that situation I would want them to be redirected to the login form (with a message encouraging them to logout and login again with suitable crede...
Thanks to @s_ha_dum I eventually tracked the issue down to the following line in my <code> wp-config.php </code> file... <code> @define('ADMIN_COOKIE_PATH', '/'); </code> Commenting this out solved the problem Ironically, I've tended to include this line as a standard preventative measure against login redirection loop...
Require re-login when logged-in user attempts to access restricted page
wordpress
In the beginning of each page served by WordPress, there is a MySQL call to fetch options: <code> SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'; </code> Because there's no index on <code> autoload </code> column, MySQL has to lookup ALL rows. I also came across the comment of stackexchange-url...
There is no index because the need for it was never strong enough. In ticket #14258 it was suggested, but since most options use <code> autoload=yes </code> by default, the index would be ignored anyway. There is also the still open ticket #24044 _Add index to wp_options to aid/improve performance_. I think you should ...
How come `wp_options` table does not have an index on `autoload`?
wordpress
I was wondering for CPT list and editing pages to show under Posts tab instead of creating its own tab. I really want to use CPT (over using categories) because I'd have control over capability and different templates. Any input is appreciated.
This can be done manipulating the global variable <code> $submenu </code> . In this example, the post type name is <code> portfolio </code> . See comments in code. <code> add_filter( 'custom_menu_order', 'move_one_post_type_wpse_98281' ); function move_one_post_type_wpse_98281( $menu_ord ) { global $submenu; // Enable ...
CPT in Posts tab instead of its own tab
wordpress
I'm trying to find a way of disabling the selection of the parent category within Wordpress 3.5.1 (post editor screen) only when that parent category contains child categories. My structure: Category 1 (no children, allow users to post, keep selection option) Galleries (parent category WITH children, remove selection o...
I disabled the parent boxes to avoid shifting parents to the left. <code> add_action( 'admin_footer-post.php', 'wpse_98274_disable_top_categories_checkboxes' ); add_action( 'admin_footer-post-new.php', 'wpse_98274_disable_top_categories_checkboxes' ); /** * Disable parent checkboxes in Post Editor. */ function wpse_982...
Make parent category not selectable when it has child categories
wordpress
I am having an issue with enabling minify with the W3TC plugin. I am using a LEMP stack and cloudfront as a CDN, and all of these features, except for the minify work fine. In order to enable fancy permaplinks in WP I added <code> /index.php?q=$uri&amp;$args </code> to the <code> try_files </code> line in sites-availab...
Try using the following for your rewrite rules: <code> location / { try_files $uri $uri/ /index.php$is_args$args; } </code> Using that schema, you can manually remove <code> index.php </code> from your Permalinks settings without breaking anything. Nginx will now check any URI for its existence as a file on the filesys...
Enable Minify in W3Total Cache using NGINX
wordpress
How can i get the category ID in the <code> archive-product.php </code> template? I tried to get this information with the <code> $category </code> var, but this var isn't accessible in this template file.
Normally this should work with <code> get_queried_object_id() </code> . Anyway, as I don't know what Woo exactly does to the query, this can be as well wrong, as the API function references to the object that is currently queried. And this is the object from the last query. So you might also do the following: Disclaime...
Get category ID in "archive-product.php"
wordpress
What I am wanting to achieve is to remove an action called inside of another action. The action is calling a style, and although I have tried to deregister, and dequeue the style, it is still displaying on the admin pages. Here is the code snippet (inside of WooCommerce): <code> function woocommerce_admin_menu() { glob...
To clean up a complete array use the helper function <code> __return_empty_array() </code> as callback: <code> add_filter( 'woocommerce_screen_ids', '__return_empty_array', ); </code> Similar helpers for further usage are: <code> __return_true() </code> <code> __return_false() </code> <code> __return_zero() </code> <co...
Removing an action, or dequeueing style - Both not working
wordpress
When we try to access a Deleted or Archived site in Multisite, WordPress shows a <code> wp_die() </code> message. And this message appears for Deleted sites: This user has elected to delete their account and the content is no longer available. How can we customize that?
The function that deals with this is <code> ms_site_check() </code> . If existent, it will use the following files. And they should render a full custom HTML page. <code> WP_CONTENT_DIR . '/blog-deleted.php' </code> <code> WP_CONTENT_DIR . '/blog-inactive.php' </code> <code> WP_CONTENT_DIR . '/blog-suspended.php' </cod...
Customizing Deleted/Archived blogs warning pages
wordpress
I'm having trouble getting post by term in a custom taxonomy I have set up. The catch is this is multisite and I'm getting this data from another blog on the network where the taxonomy is registered. The code I have works fine on the blog with which the taxonomy is registered. However when I try the same code on the ot...
Solution (or at least in part) The problem is switch_to_blog doesn't give you access to everything in another blog on the network including taxonomies, tags, things in your functions.php, although don't quote me 100% on that. Therefore the taxonomy wasn't registered in the "switched to" blog. My solution (at least for ...
Get post by term from custom taxonomy in another blog on the network?
wordpress
I want to in insert data in my custom db table when creating a post. Suppose there are three categories (php, wordpress &amp; jquery). When i create a post in wordpress, i want to insert post id and category id in my custom database table. How can i do this job?
You hook a function to <code> save_post </code> (for saves and updates) or <code> publish_post </code> for publication only. The second hook is really a variable hook of the form <code> {$new_status}_{$post-&gt;post_type} </code> so it will be different if you aren't dealing with a <code> post </code> post type. <code>...
Insert data in custom table during new post creation
wordpress
I have a wordpress site with a few plugins. I had to make some custom changes on a plugin (not a best practice), and of course I don't want to update that plugin. But for some reason all my plugins have been updating themselves automatically without asking. ( Is that even possible ?!!). I have never had this behavior b...
I found my problem: Once I have updated a plugin through the wordpress admin section once, it will continue to update it automatically whenever there is a new version of this plugin. I didn't know this behavior. I was hoping I would need to click the 'automatically update' message on the plugin every time I wanted to u...
Why my plugins are updating automatically?
wordpress
I'm creating a website and I'd like to be able to reuse the same slug/post name in the page's url. ex using <code> /%category%/%postname% </code> <code> foo.com/bar/page foo.com/barz/page // Will not work. Instead it will use page-2. </code> I've done some research and it doesn't look like it's possible to do what I wa...
This is not natively possible, since in your example permalink structure posts are detected by slug alone, and not combination with category. Essentially category info gets simply discarded. If your requirements involve only one (few) of possible endings for URL you might achieve this relatively easy using endpoints, s...
Using one slug/post-name for multiple pages
wordpress
Im currently printing out: <code> &lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'primary' ) ); ?&gt; </code> Which outputs: <code> &lt;div class="menu"&gt; &lt;ul&gt; &lt;li class="current_page_item"&gt;Frontpage&lt;/li&gt; &lt;li class="page_item page-item-2"&gt;etc&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code> In...
Use the arguments <code> before </code> and <code> after </code> : <code> wp_nav_menu( array( 'theme_location' =&gt; 'primary', 'menu_class' =&gt; 'nav-menu', 'before' =&gt; '&lt;span&gt;', 'after' =&gt; '&lt;/span&gt;' ) ); </code> To see how these arguments are used, look at the method <code> start_el() </code> in <c...
Add within the output of
wordpress
In my functions.php I have the following code: <code> add_action( 'admin_menu', 'jp_create_admin_pages' ); function jp_create_admin_pages() { add_menu_page( 'Members', 'Members', 'manage_options', 'members', 'admin-members.php'); } </code> In the same folder, I have another file called admin-members.php with the follow...
You can’t. Create a function that loads that file: <code> function load_admin_page_file() { require 'admin-members.php'; } </code> Then use that function name as callback argument. In PHP 5.3 you can use a lambda: <code> add_menu_page( 'Members', 'Members', 'manage_options', 'members', function() { require 'admin-membe...
Reference external file as a function
wordpress
I want to create a custom post type for store that having all store names and it is working. Now I want to fetch the all stores in a select box in every new post of WordPress, then selected store name will used as custom field for that post. I want to save this store name as meta value for this post in <code> wp_postme...
To get the posts from a post type you can use <code> get_posts() </code> <code> $posts = get_posts( array ( 'numberposts' =&gt; -1, 'posts_per_page' =&gt; -1, 'post_type' =&gt; 'store' ) ); </code> Be aware, the <code> -1 </code> is dangerous: If there are millions of stores, the query might run into a time-out. Here i...
Use Custom Post Type as Custom Field
wordpress
I currently enque jQuery like so - how do I move this to the footer instead? <code> // Enque: jQuery if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11); function my_jquery_enqueue() { wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : ""...
The fifth parameter is <code> $in_footer </code> . You have left that out. Add that parameter, set it to <code> true </code> . <code> wp_register_script( 'jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null, true ); </code> But I ech...
Enque Javascript in Footer?
wordpress
I published a plugin and then installed it into a test site to check it was published OK. The copy that was installed contains: plugin.php readme.txt trunk/plugin.php trunk/readme.txt The trunk folder is redundant and other plugins don't seem to come duplicated. How can I avoid the plugin files getting downloaded twice...
I do not know which OS and/or software you use but regarding SVN it's quite simple : $ svn co http://plugins.svn.wordpress.org/your-plugin-name Then you just have to add your files in trunk and/or maybe in assets (banner,screenshots). Then : $ svn add trunk/* and or : $ svn add assets/* Last step is : $ svn ci -m "init...
How do I avoid having duplicate of plugin in trunk?
wordpress
I've set up a custom post type and would like to have the ability to attach files to those posts. I've got the CPT and metabox set up, and the upload function as well. When I display the CPT on the front end, I'd like there to be a download link for the file. To simplify things, I'd like to use the included MIME type i...
Ended up using <code> wp_handle_upload() </code> , which puts MIME type into the DB automatically. See http://codex.wordpress.org/Function_Reference/wp_handle_upload One thing to note, this function enters the file in the DB as post meta and not as an attachment. <code> wp_insert_attachment() </code> would do the latte...
How to add filetype to meta value when using wp_upload_bits?
wordpress
So, I've run into what looks like a WP RAM usage problem and am looking for a solution. The only place I'm really having this problem on my site is with a Site Map page that I'm trying to populate, but a solution to this problem could be universally applied and save on RAM usage across an entire site. Essentially, this...
You can try a trick with querying post data directly and setting <code> filter </code> field of post objects to <code> sample </code> before passing it to <code> get_permalink() </code> to reduce memory usage. See get_permalink memory usage issue for detailed reasoning behind it.
Is there a way to exclude the content from the post variable to save on RAM usage?
wordpress
I have been spending a lot of time the past few months researching on how to create my first theme. That said most tutorials/books only discuss static sites and I want to go about this well prepared. I would like to add a gallery only on my home page. I have already created an HTML5 mockup of the gallery using jQuery s...
WordPress has rather convoluted logic for front and home page (which often, but not always are the same thing). It depends on your needs what approach is best to take - for example are you making this as theme for private use or public redistribution, do you want page customized completely or just add elements to it. T...
Adding a gallery to my first theme
wordpress
I was curious if was possible to display related posts by multiple tags. The site I am working on has about 5 tags per post. Most posts have 1 or 2 tags in common. The related posts I'd like to show have 3-5 tags in common. So, I'd like the related posts to function by looking for posts with the most number of tags in ...
I had the same idea and wrote a small little plugin to help me do this. <code> function get_pew_related_data($args, $post_id, $related_id) { global $post, $wpdb; $post_id = intval( $post_id ); if( !$post_id &amp;&amp; $post-&gt;ID ) { $post_id = $post-&gt;ID; } if( !$post_id ) { return false; } $defaults = array( 'taxo...
Related Posts by Multiple Tags?
wordpress
I've add the field country in the comment form. Working nice and I can see the value in the table commentmeta. Now I try to display this value in my comment list. In my single.php I call the list of comments: <code> &lt;?php wp_list_comments('type=comment&amp;callback=format_comment'); ?&gt; </code> In my functions.php...
Looking at the Codex entry for <code> get_comment_meta() </code> , it appears that when the <code> $single </code> argument is set to <code> TRUE </code> (as you have done), the function returns a string. Try throwing an <code> echo() </code> into the works: <code> &lt;?php echo get_comment_meta( $comment-&gt;comment_I...
How to get a value from comment meta
wordpress
I've added to my theme a new custom taxonomy in order to add future filtering capabilities to a custom post type called 'product' (I use the wooCommerce plugin which defines this custom post type). <code> $labels = array( 'name' =&gt; _x( 'Types de produit', 'Taxonomy General Name', 'my-child-theme' ), 'singular_name' ...
Without changing anything, everything seems OK today. The auto-suggest works and suggests me existing tags when I begin to type a word... I don't know why but maybe there was a problem because I've firstly created this custom taxonomy as hierachical before I decided to change it to non-hierarchical.
Custom taxonomy auto suggest not working in wordpress admin
wordpress
Is it possible to display a featured image on a news page that uses index.php? I'm currently using wp_query to display posts from a specific category on the news page. Each post has his own featured image which isn't displayed on the index/news page but only for the post itself. If i place <code> &lt;?php the_post_thum...
If I am reading your question correctly, the problem is that when you set a page so that it has a an archive Loop on it <code> $wp_query </code> and the <code> $posts </code> variable are set to for the index Loop and not for the page the are on. To get information about that page you need <code> get_queried_object </c...
Featured image for news page
wordpress
I have a query that loops through <code> &lt;li&gt; </code> 's and displays the number of <code> &lt;li&gt; </code> 's I have. Is there a way I can make the loop pull 2 <code> &lt;li&gt; </code> 's at a time rather than one? <code> // 5 list items &lt;ul&gt; &lt;?php while(has_posts()): the_post(); ?&gt; &lt;li&gt; &lt...
Easy using WP query (get to know it...) <code> &lt;ul&gt; &lt;?php $recentPosts = new WP_Query(); $recentPosts-&gt;query('showposts=2'); // SET AMOUNT HERE ?&gt; &lt;?php while ($recentPosts-&gt;have_posts()) : $recentPosts-&gt;the_post(); ?&gt; &lt;li&gt;&lt;div class="slide"&gt;&lt;?php the_content(); ?&gt;&lt;/div&g...
Output 2 items within the Loop
wordpress
Updating some meta fields on registration and providing the user the option to pick a password yet the registration email sends the auto generated password. User defined password works and not emailed pass. <code> add_action( 'user_register', 'jwh_register_extra_fields', 100 ); function jwh_register_extra_fields( $user...
Welcome to WPSE. You can use wp_insert_user , you don't need to hook onto anything. Assuming here they fill out a form with a name, username, email and password field, and you capture it however you want. <code> $name_array = explode(' ',$_POST['name']); $user = array( 'user_login' =&gt; $_POST['username'], 'user_pass'...
User defined password at registration - registration email sends auto generated pass
wordpress
I've a piece of code that shows a banner the first time a user visits, then sets a cookie, which prevents it showing again. However, if the page has a 404 error, the 404 page of the requested resource sets the cookie and the banner is not shown. Checking <code> is_404() </code> on the init hook does not avoid this situ...
Use a later action hook You cannot use Conditional Tags before the <code> posts_selection </code> hook has run (as per the codex), which happens right after <code> pre_get_posts </code> and quite a bit after <code> init </code> . Hence, would it not be easier to set the cookie at a later stage of the request, rather th...
Detect 404 before headers are sent
wordpress
I'm trying to work which plugin is triggering wp-cron. I know about the code: http://codex.wordpress.org/Function_Reference/wp_get_schedules , but I'd prefer to do something in the sql backend rather than write a plugin.
Why don't you just create a cron job, make a database dump and look where the info about the cron job is kept? That's what I did. As suspected, WordPress 3.5.1 keeps its cron jobs in the <code> {wp}_options </code> table under the name <code> 'cron' </code> . <code> SELECT * FROM `wp_options` WHERE `option_name` LIKE '...
Is there a quick way to view the wp-cron schedule
wordpress
I'd like to change where the 'Howdy' link gets you when you click on it. I have a website with buddypress and instead of getting users to their profile page I want to get them to their 'Activity' tab. How can I change the link? Thanks, Kat
It's not well documented, but the <code> add_node </code> and <code> add_menu </code> methods of the <code> WP_Admin_Bar </code> class can be used not only to create new menu or nodes, but also to update an existing menu or node. So i went ahead and tracked down the code that WordPress initially uses to create that ite...
Change the link of 'Howdy' at the top right
wordpress
I created a <code> shortcode </code> to make an HTML5 player insert into my post, but my problem is when I attempt to view a video that I've uploaded with the native <code> Media Uploader </code> , I get a file not found error. The test video I used is an <code> .mp4 </code> . Is there a block on using videos in the <c...
Ok, I found the problem. It wasn't a <code> Wordpress </code> problem, but a server issue. I had to add the file extension <code> .mp4 </code> with MIME type <code> video/mp4 </code> in the MIME types of the IIS server. Here is the link I found with the steps to correct the issue: http://forums.asp.net/t/1470612.aspx/1...
Video uploaded with the native media uploader gives Error 404
wordpress
I'm trying to load two JS files. But some how its not working. Tried both of these, and the console window doesn't complain of unable to load the file, it never was in the head. Also, I'm having a weird issue (not sure if related) that CSS file would not be loaded if not specified explicitly in the header. However, if ...
Whenever building a theme, you should always add wp_footer(); in the footer.php right before the closing body tag to ensure all JS files that are loaded at the footer can be loaded.
Can't load JS File
wordpress
I'm aware that one can add a control to the theme customiser to add an image. This control returns an image URL however, and I need its attachment ID, not the image URL. Where can I intercept or steal the attachment ID of this image in order to do this? Is there a save hook I can intercept? Or a javascript based method...
The solution, needs a custom control object extending the original image control, and does an SQL query to grab the GUID and associated attachment ID on sanitisation. Not nice, kludgey, but it works <code> $wp_customize-&gt;add_setting( 'customimage', array( 'default' =&gt; $default, 'capability' =&gt; 'edit_theme_opti...
Theme Customiser Image Control
wordpress
I ran into an issue with a site that needs the category base also included in the custom permalink structure. I know this is an issue and I have read many posts like stackexchange-url ("this") that gave me some insight... I need to get the permalinks to work like this: <code> http://www.new1450.dev/industries/ {Main bl...
I was able to get this to work pretty easily actually. I am now able to have my category base in my permalinks. This allows me to now have URLs like: <code> http://www.new1450.dev/industries/ {Main blog post only showing category selection} http://www.new1450.dev/industries/development/ {a parent category} http://www.n...
How to get permalinks with category base working with sub-categories
wordpress
The code below produces a sub-menu of child categories of the currently active parent category. This code also produces the child categories of the top parent category while viewing child categories and posts in those categories. The <code> .current-cat </code> CSS class is applied to the active child categories. This ...
very similar approach to the answer by @AndrettiMilas: <code> add_filter('wp_list_categories','style_current_cat_single_post'); // filter to add the .current-cat class to categories list in single post function style_current_cat_single_post($output) { if( is_single() ) : global $post; foreach ( get_the_category($post-&...
Add Class While on Current Post; wp_list_categories
wordpress
I am trying to make a simple media manager on the front end of my posts, as my site will have many authors. I want to give them the ability to delete any picture attachments that they have uploaded to their posts ( without having access to the media manager, because I want this to be mobile compatible). From my researc...
You can do it via ajax, first, let's change your current function to this: <code> &lt;?php $args = array( 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order', 'post_type' =&gt; 'attachment', 'post_parent' =&gt; $post-&gt;ID, 'post_mime_type' =&gt; 'image', 'post_status' =&gt; null, 'numberposts' =&gt; -1, ); $images = ge...
Delete attachments from Front end
wordpress
I'm working on an updated version of an existing plugin. In the readme.txt file, I'll be adding an entry to the "Upgrade Notice" section, which will show up in users' Plugins admin page when the new version gets released. I see from the official readme.txt format that this field is limited to 300 characters. My questio...
I haven't confirmed the behavior of the Plugins admin screen, but using the official readme.txt validator , I see that the validator has stripped away the link that I put into the Upgrade Notice section. Judging from that, it looks like the answer is no.
Are links allowed in the Upgrade Notice section of a plugin's readme.txt file?
wordpress
I'm having trouble seeing why categories are not appearing for Knowledge Base and Articles. What's wrong with this code? <code> &lt;?php // Custom post types /* faq */ add_action( 'init', 'faq_post_type' ); if ( ! function_exists( 'faq_post_type' ) ) { function faq_post_type() { //Register FAQ Post Type register_post_t...
Your Knowledgebase and Articles CPT slugs are capitalized. This is not allowed - see the codex . (string) (required) Post type. (max. 20 characters, can not contain capital letters or spaces) Change these to all lower case, both in the first parameter of the <code> register_post_type </code> and in the second parameter...
Missing categories for Custom Taxonomy and Custom Posts
wordpress
this was kinda of a joke at the beginning but now I'm wondering if it's possible to use regex with the hook comment_form_defaults. Here is what I'm looking for : <code> function remove_default_allowed_tags( $defaults) { $defaults = preg_replace('/&lt;p class="form-allowed-tags"&gt;(.*?)&lt;\/p&gt;/','', $defaults); ret...
You can use regex anywhere you have a string to manipulate. That is basic PHP. There is nothing special about WordPress that changes that. But why use regex when there are other options? As much fun as it is, regex is tricky and easy to get wrong, and there is significant overhead to using it. What you are doing genera...
preg_replace and comment_form_defaults
wordpress
If I will use an array of email IDs for $to parameter of wp_mail function, will it send different emails to all those email ids or will send one email with all the email ids as 'to'?
Yes, you can use an array of recipients: <code> * @param string|array $to Array or comma-separated list of email addresses to send message. * @param string $subject Email subject * @param string $message Message contents * @param string|array $headers Optional. Additional headers. * @param string|array $attachments Opt...
wp_mail: An array as $to - multiple emails or single email with all the email ids in it?
wordpress