question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
This is my first time writing plugin. I have managed to get options menu with the html form: <code> &lt;?php add_action('admin_menu', 'menu'); function menu(){ add_options_page("poster","poster",'manage_options',"poster",'option_page_html'); } function option_page_html(){ ?&gt; &lt;div&gt; &lt;form action="wp-content/p...
You should post to the same URL and catch the submit ex: <code> function option_page_html(){ if (isset($_POST['plugin_action']) &amp;&amp; $_POST['plugin_action'] == 'post_url'){ include_once(plugin_dir_path(__FILE__).'post-video.php'); } ?&gt; &lt;div&gt; &lt;form action="" method="post"&gt; &lt;p&gt;&lt;h3&gt;Paste v...
Doing action based on input from options menu
wordpress
I have a custom field value that is an array and it has date as one of the values: <code> a:3:{s:4:"date";s:10:"03/06/2013";s:6:"target";d:1000;s:8:"currency";s:3:"USD";} </code> I'm trying to sort posts with this date but I'm having trouble doing it. Here is my query: <code> $args = array ( 'showposts' =&gt; -1, 'post...
Sadly you can't. You can't query based on serialized data and since you store the data in an array it is saved as serialized. you should use a separate row for each field you want to query / sort based on. I asked this same question about two years ago .
Sorting posts by custom field value in array
wordpress
I have added a link on the footer of my page in the format <code> &lt;a href="URL"&gt;Link&lt;/a&gt; </code> I would like to allow wmpl to translate it in french and have tried scanning my theme but the link's text doesn't appear in the string translation manager in the dashboard. After reading this: http://wpml.org/fa...
You need to put your strings in translatable format. <code> &lt;a href="URL"&gt;&lt;?php _e( 'Link', 'your-theme-text-domain'); ?&gt;&lt;/a&gt; </code> Function reference: <code> _e() </code> , this one <code> echo </code> es the value, for assignment, use <code> $my_string = __( 'String', 'text-domain' ); </code> . Al...
Cannot locate specific link/string using String Translation with WPML?
wordpress
How could I add a description to <code> $wp_customize-&gt;add_control </code> ? I've found I really need to include a short description on some of the controls but it doesn't look like it's possible. I noticed you can add a description to <code> $wp_customize-&gt;add_section </code> but that's only a tooltip. This is i...
Here is one way to do it by extending the control you want to use. Below is an example where we extend the text control and add an extra description like the one seen here on the screenshot: <code> function mytheme_customizer( $wp_customize ) { class Custom_Text_Control extends WP_Customize_Control { public $type = 'cu...
Adding a description to theme customizer controls
wordpress
I have a gallery that contains both landscape and portrait pictures and want the gallery to be displayed in the wordpress sidebar. The problem is that the thumbnails of the portraits are scaled into landscape format which is unacceptable. Is there a way to exclude portrait pictures? Or is there a way to keep the ratio ...
There are several things you could do to achieve what you want. You could: create a new gallery with just the landscape images and include this new gallery into the sidebar; try different thumbnail settings in the NGG options (ignore aspect ratio or not, set height and width to the same value and thus show quadratic im...
How do I exclude portrait pictures from the nextgen gallery sidebar widget?
wordpress
<code> is_feed </code> (one of the many conditional tags ) can be used to determine if the current query is for a feed. But how do I use it to target all category feeds? (or tag or custom taxonomy feeds for that matter) This doesn't seem right: <code> if (is_category()) { if (is_feed()) { // Code Goes here } } </code> ...
If you want to determine if you are in a category feed, for example: <code> http://example.com/category/football/feed </code> you can do so with <code> add_action('wp', 'mycheck'); function mycheck() { if(is_feed() &amp;&amp; is_category() ){ // do stuff } } </code> or <code> add_action('wp', 'mycheck'); function myche...
How to use is_feed() to target a category feed?
wordpress
I'm using the following line to show content from one page on another. This line outputs the content's raw text of a shortcode: <code> &lt;?php $id=3934; $post = get_page($id); $content = apply_filters('the_content', $post-&gt;post_content); echo $content; ?&gt; </code> How can I add to or filter this snippet to allow ...
If you want to display the shortcodes in the string variable <code> $content </code> you can use the Wordpress function <code> do_shortcode() </code> like this: <code> echo do_shortcode($content); </code> See more in the Codex: http://codex.wordpress.org/Function_Reference/do_shortcode
Filter Shortcodes when using get_page
wordpress
I'd like to include a functionality in a theme that will overwrite styles from previously included CSS files. For this purpose, I need to be able to display a <code> &lt;style&gt; </code> in the header after ALL stylesheets have been displayed. Is there a hook to do this?
Hook to <code> wp_enqueue_scripts </code> with a high priority number. For example: <code> function load_my_style_wpse_90225() { wp_register_style( 'mystyle', get_template_directory_uri() .'/path/to/stylesheet.css'); wp_enqueue_style( 'mystyle' ); } add_action('wp_enqueue_scripts','load_my_style_wpse_90225',1000); </co...
Display Something in the Header After All Styles are Loaded
wordpress
What I am trying to do? My blog uses a custom taxonomy called <code> edition </code> with terms like <code> us-canada </code> (6), <code> eu </code> (7) and <code> india </code> (8) -- term slug (ID). I want to make sure that posts not assigned to any specific 'edition' be shown under all the terms (i.e. if a post is n...
I'll take another shot. The following should modify the main query, such that it will include in its loop any posts that belong to no term of the Edition custom taxonomy . <code> add_filter('pre_get_posts','better_editions_archive'); function better_editions_archive( $query ) { if ( $query-&gt;is_tax( 'edition' ) &amp;...
Include and Exclude Taxonomies From Archives & Feeds Using 'pre_get_posts'
wordpress
I'm about to start writing a php file that will return a JSON array to be used as a JQuery autocomplete source. I want to create my source.php file that loads without the WordPress template. Currently /includes/source.php contains: <code> &lt;?php echo "hello world"; ?&gt; </code> But if I go to http://www.mywordpress....
why don't you use Wordpress ajax hooks. It is really simple. first call the function from javascript or jQuery use the key as 'action' and value as 'function hook name' <code> jQuery(document).ready(function($) { var data = { action: 'my_action', // here is the function name whatever: 1234 // if there are the data you ...
JQuery load php - php file without the template
wordpress
I'm designing a new theme and in my page template a have a section where an image is displayed . I would like this image to change depending on which page is loaded. The section is a DIV like this: <code> &lt;DIV class="ximage"&gt;&lt;/DIV&gt; </code> What I would like to do is to add a class to the DIV depending om pa...
You might want to consider using the Wordpress function <code> body_class() </code> <code> &lt;body &lt;?php body_class($class); ?&gt;&gt; </code> Then you could use the body class as your current page reference. This function is for example used by the Twenty-Twelve theme. For a single post it will become <code> &lt;b...
Add class to DIV depending on page loaded
wordpress
I check the below answer to rename files during upload and tries to change it to something like postid_originalfilename.jpg but failed. Any help? <code> function make_filename_hash($filename) { $info = pathinfo($filename); $ext = empty($info['extension']) ? '' : '.' . $info['extension']; $name = basename($filename, $ex...
If you want to use the above <code> sanitize_file_name </code> filter, you could try this: <code> function make_filename_hash($filename) { if( isset($_REQUEST['post_id']) ) { $post_id = (int)$_REQUEST['post_id']; }else{ $post_id=0; } $info = pathinfo($filename); $ext = empty($info['extension']) ? '' : '.' . $info['exte...
Change filename during upload
wordpress
Introduction In optimizing large WordPress Websites for performance I always look at caching certain parts of the Website, mostly (of course) those that require a lot of Queries/calculation. For the Caching of the WordPress menu I usually use a function like the one I posted as an Answer stackexchange-url ("here"). Thi...
There is no generic solution for this problem: The same menu can be rendered with different walkers on different pages, or plugins change the menu on some pages. You could extend your script to evaluate the differences to an untouched menu and build the necessary JavaScript on the fly … and cache that too … for each si...
Should the caching of WordPress menus be specific to each page?
wordpress
How can I take my table I created like this: <code> global $wpdb; //Get all the wordpress database stuff $table_prefix = $wpdb-&gt;base_prefix; //Get the global prefix for all sites (on a multisite installation) $table_name = $table_prefix.'wpaa';//Add wpaa behind the prefix $sql = "CREATE TABLE IF NOT EXISTS `".$table...
<code> $wpdb-&gt;get_results(); </code> has a second parameter for the return format: <code> /** * Retrieve an entire SQL result set from the database (i.e., many rows) * * Executes a SQL query and returns the entire SQL result. * * @since 0.71 * * @param string $query SQL query. * @param string $output Optional. * Any...
Get a custom table to an array
wordpress
I am starting to learn how to write plugins for Wordpress. I'm interested in using WP as a CMS for long essays (6000-9000 words or more). My problem is what I call the Kindle problem, which is how do you reliably address the different parts of an unpaginated document which can be read on a variety of screens/devices, a...
You could probably achieve this with a filter of some sort on <code> the_content </code> . Here's a quick and dirty example that finds all instances of <code> &lt;p&gt; </code> and inserts a named anchor, then adds a list of links to each anchor at the top of the content. Check out the Shortcode API as well, which coul...
Numbering sections and block-level elements in wpautop(); Wordpress as CMS for long-form writing;
wordpress
I would like to enhance the Media Editor, after WordPress 3.5, on the gallery view. I want to add a new select field on the right side and send the selected values to the gallery shortcode. I think, the function <code> wp.media.gallery </code> in <code> wp-includes/js/media-editor.js </code> is the default function to ...
A small source, perhaps for a plugin to create the solution. At first the php part, there include the javascript for the button inside the Media Manager. Is more usable answer, but the answer of @One Trick Pony was create and the right direction and JS solution. See the result on the image: The resulting shortcode, if ...
Enhance Media Manager for Gallery
wordpress
UPDATE: I have worked out my implementation of the selected answer at the bottom of this post. I'm implementing a sorting algorithm based on Reddit's hotness algorithm , in addition to a time-decay (like Hacker News hotness algorithm ). The code I am currently satisfied with is a result of trial and errors in some Exce...
The other day I was thinking on how to make something like this, I would recommend to save the hottnes as a post meta value, that is updated on every vote, save or update, for that you will need the save_posts filter and then you can get the posts ordered with pre_get_posts and a meta query something like <code> $query...
Using database meta_values to calculate new post order using pre_get_posts or a 'request' hook
wordpress
I'm using <code> Post templates </code> plugin. But its very outdated. I'm getting <code> Warning: Illegal offset type </code> at this line <code> $templates = $themes[$theme]['Template Files']; </code> Here is my full function code. <code> function get_post_templates() { $themes = wp_get_themes(); $theme = wp_get_them...
The Line <code> $theme = wp_get_theme(); </code> returns a <code> WP_Theme </code> Object, and you cannot use an Object in an <code> Array </code> like this. Use <code> $templates = $themes[$theme-&gt;template]['Template Files']; </code> To get the <code> Array </code> of your template Files. In Order to get this funct...
wp_get_theme Warning: Illegal offset type
wordpress
My loop displays posts in two columns using this php <code> &lt;?php if (have_posts()): while (have_posts()) : the_post(); $count++; ?&gt; &lt;?php if ($count == 1) : ?&gt; &lt;div class="home-ci-row"&gt; &lt;div style="padding: 0px;" class="main-column-item-wrap"&gt; CONTENT OF POST : Title, Thumbnail, Excerpt... etc ...
You could do this much easier. As you are making a layout that can be achieved by floats, there is no need to declare a Row every second time. In my Code example I just youse the <code> $count </code> to determine the Class of the HTML-Element. In combination with the total Number of Posts displayed. If the total numbe...
If Loop has odd number of posts on last page Custom style for last post in it
wordpress
In this Q&amp;A, stackexchange-url ("How do you change the visual editor&#39;s background color?"), it is shown how to modify WordPress' editor background colour. My question is how can I modify the editor's background colour, in full screen mode? (also called "distraction free" mode). The solution in the linked thread...
This kind of problems are solved using Chrome Inspector or Firefox Firebug . Inspecting the element, we get the necessary ID's or Classes to add in the stylesheet. So, <code> .mceContentBody.wp-fullscreen-editor </code> is the one we need to address in the theme file <code> editor-style.css </code> : <code> .mceContent...
Editor background colour in full screen
wordpress
I've created a menu page using the following function: <code> add_menu_page( 'Nonpareil options', 'Nonpareil options', 'administrator', 'nonpareil_theme_options', 'nonpareil_theme_display' ); </code> Now I want to load a js file only on this page. I'm trying to do so properly by enqueueing it only on my new page: <code...
You could try replacing <code> if( 'nonpareil_theme_options' != $hook ) </code> with <code> if( 'toplevel_page_nonpareil_theme_options' != $hook ) </code> if you have the custom menu added like this: <code> add_action('admin_menu', 'register_custom_menu_page'); function register_custom_menu_page() { add_menu_page('Nonp...
Enqueueing Scripts on a Custom Top-level Menu Page
wordpress
I'm using taxonomy categories to show my custom post type, but when I click on it, no page is linked. How do I create a page to display the results from categories? I tryed like custom post type: <code> category-portfolio.php </code> but not worked.
Did you create taxonomy-{your-slug}.php template ? let's say the slug is ' locations ' so, it will be something like this taxonomy-locations.php if you haven't created yet, create one and the template codes will look like this , <code> &lt;?php /** * Locations taxonomy archive */ get_header(); $term = get_term_by( 'slu...
Display one result for category post type
wordpress
Hi I'm trying to make a page template that shows a list of a custom post type ordered by a meta key, I easily made it with <code> query_posts </code> but I am trying to do it via <code> pre_get_posts </code> so I made a function like this: <code> add_action('pre_get_posts', 'events'); function events($query) { if ( is_...
I'm not sure this is possible. Why do you need a page template? Why can't you use a custom post type archive, which is built-in to WordPress ( if you register the post type with <code> has_archive </code> set to true). I'm ignoring all your other possible $args, because I don't know how you are registering this post ty...
Custom post types loop on a page template
wordpress
I have a front-end form where people can submit their website URL. I'm actually verifying URLs in Wordpress with a PHP function and I would like to know if there is a built-in function that allows me to do this ? This is the function that I am actually using : <code> function validateURL($URL) { $v = "/^(http|https|ftp...
Use <code> esc_url( $url ) </code> for URLs that should be displayed and <code> esc_url_raw( $url ) </code> if the URL should be sent to the database. The first will replace bare ampersands <code> &amp; </code> with <code> &amp;#038; </code> . The second is a wrapper for the first; it will just suppress the escaping of...
Built-in data validation function for URLs
wordpress
I am trying to use information about the current user in a plugin that I am designing and I have seen people go about it in several different ways. My Way This way seems to work, but am I missing something? <code> global $current_user; // Use information echo "User ID: " . $current_user-&gt;user_id; echo "User First Na...
1, call the function get_currentuserinfo() on the next line after declaring the global variable $current_user 2, what is the difference between wp_get_current_user() and get_currentuserinfo()? <code> function wp_get_current_user() { global $current_user; get_currentuserinfo(); return $current_user; } </code> I think th...
Getting the Current User
wordpress
I have a load of custom widgets that all look pretty much the same. I have a multisite blog with 3 blogs. The widgets are configured individually to show up on all 3 blogs with their own settings in Appearance -> Widgets. All widgets show normally on the first, main blog. On the other blogs, some of the widgets don't a...
I got a Tumbleweed badge for this :( FWIW I eventually "fixed" this by restoring the database from backup and recreating the theme files afresh with a new theme name and directory. It seems like a lot more effort than it should be. I figure there was some kind of weird database corruption / conflict somewhere that made...
Some widgets on Multisite not showing up in template for particular theme
wordpress
I have a field on my portfolio admin page which shows the url when the user write a url(obviosly). I want to when the user write in the field, elements appear along with it. And if the field is empty dont shows anything. The code that shows what the user is writing in this field is: <code> &lt;?php echo get_post_meta($...
Just write a if statement using the <code> get_post_meta </code> like this <code> &lt;?php if(get_post_meta($post-&gt;ID, '_url', true)){?&gt; &lt;p&gt; Display some stuff.&lt;/p&gt; &lt;?php } ?&gt; </code> There is an example here http://codex.wordpress.org/Function_Reference/get_post_meta
Custom Portfolio String
wordpress
I'd like to ONLY show the authors website link if it exists, but I can't work out the exact syntax for it. I have this <code> if ( get_the_author_meta('user_url') ) : // If a user has filled out their decscription show a bio on their entries echo the_author_meta('user_url'); endif; </code> But I need to wrap it in a li...
Try passing $user_ID global variable to function as following. it is working for me. <code> &lt;?php global $user_ID; if ( get_the_author_meta('user_url',$user_ID) ) : // If a user has filled out their decscription show a bio on their entries ?&gt; &lt;a class="meta-website" href="&lt;?php the_author_meta('user_url',$u...
Author_meta ONLY if it exists
wordpress
I'm looking for a way to update a wordpress website when I post something to a specific twitter or facebook account. Is it possible? Is there any plugin that do this? I find only plugins that do the inverse, updating social networks from WordPress. What I'd like to do is to update WordPress from my social network accou...
You can do this with the If This Then That service. You will have to enable posting via XML-RPC (enabled by default in WP 3.5+), Then you can create a recipe which uses Twitter or FaceBook as the trigger, and WordPress as the action. If you poke around, someone has probably already created these recipes .
Update a WordPress website FROM Twitter or Facebook
wordpress
I've been hunting for the hook to edit the Biographical info field and it's H3 but no luck. I've found edit_user_{$field} do specific hooks exist? I'm thinking I can hook into the existing tag 'description'? Thanks in advance. <code> edit_user_profile('description', 'change_description'); function change_description(){...
thanks @toscho A quick tweak on toscho's Remove Bio Box code <code> add_action( 'personal_options', array ( 'T5_Hide_Profile_Bio_Box', 'start' ) ); /** * Captures the part with the biobox in an output buffer and removes it. * * @author Thomas Scholz, &lt;info@toscho.de&gt; * */ class T5_Hide_Profile_Bio_Box { /** * Cal...
Modify Profile Biographical Info Field
wordpress
I know that it's possible to switch the WP locale by using URL paramaters, stackexchange-url ("as described here"), but I'm trying to build a method that would entirely rely on a custom "Language" taxonomy. What I currently have is a simple plugin, that registers the language taxonomy and implements a locale switch if ...
You might be interested in url_to_postid function Used as follows from your wpsx_redefine_locale function: <code> $url = $_SERVER['REQUEST_URI']; $postid = url_to_postid( $url ); </code> Note that this does not return the post id for custom post types but the function is located in /wp-includes/rewrite.php and might be...
Locale switching with a "language" taxonomy
wordpress
WP has me pulling my hair out at the moment (past few days trying to solve). Trying to do some simple shortcodes which wrap around various points of an article. However wpautop() I believe is wreaking havoc. Ive tried various suggestions found around the net including viperbonds ( http://www.viper007bond.com/2009/11/22...
Guess then the way to fix this is to wrap the content in <code> &lt;p&gt; </code> tags as a hack to get around it. Seems the only way as WP wont detect it properly.
Wrap Shortcodes and wpautop
wordpress
everyone: this question seems pretty commmon to ask, but I did not find any answer. I was wondering, if there is a php function that I could use to direct a user to the site's registartion page, so that I can use php instead of link that I need to customize every time I change the link. THank you
It's simple, use the function <code> is_user_logged_in </code> : <code> &lt;?php if ( is_user_logged_in() ) { ?&gt; &lt;a hef="link-for-logged-users"&gt;&lt;/a&gt; &lt;?php } else { ?&gt; &lt;a hef="link-for-users-not-logged-in"&gt;&lt;/a&gt; &lt;?php } ?&gt; </code> See here http://codex.wordpress.org/Function_Referen...
Is there a way to direct unregistered user to registration page when click a link?
wordpress
I am creating a plugin that users can create forms with. Then the user will be able to input a shortcode to display this form. The shortcode will be the form name, which is stored as a <code> meta_value </code> in the <code> wp_postmeta </code> table. When the user uses a shortcode, how do I refer back to the form name...
You could use it like <code> [form id="abc123"] </code> where the value of <code> id </code> is the <code> meta_value </code> . You could generate the shortcode so the user can easily copy/paste it into the editor. Or even have a custom made button in the editor to insert it. You can check how it's done in other plugin...
Shortcodes that are created based on user input information
wordpress
I just found out that the Yet Another Related Posts plugin (YARPP) uses FULLTEXT indexes on the wp-posts table, which greatly slows down sites with a large amount of posts. Can I can just delete the plugin, or do I have to clean out the wp-posts table of those indexes in order to fix the issue?
YARPP doesn't do anything on uninstall. So you have to uninstall it then go remove the indexes manually from the DB. The index names should be prefixed with <code> yarpp_ </code> . Very untested SQL follows: <code> SHOW INDEXES ON wp_posts; DROP INDEX yarpp_title ON wp_posts; DROP INDEX yarpp_content ON wp_posts; </cod...
Fixing YARPP plugin FULLTEXT MySQL indexing
wordpress
I have been trying to figure out how to escape quotes (single and double) from shortcode attributes. Basically the content is written by the user and therefore can potentially include " and ' quotes. Problem being, with " quotes it is stopping the shortcode attribute from functioning eg: attibute="some text here with "...
It seems you are working on the wrong end. Try sanitizing the user input, for instance by means of <code> sanitize_textfield </code> , not the shortcode output.
Escaping quotes from shortcode attributes
wordpress
(WordPress 3.5.1, theme 20-11) I would like to use the red colored areas left and right to a post and can't find information on what plugin might deal with that. How can I add content there - widgets f.x. Or would I have to change the theme? I would prefer to not alter the code for this purpose.
Here's how to get a sidebar next to pages and single-post pages: Install " Twenty Eleven Theme Extensions " Go to Appearance > Theme Extensions Select "Enable the widget sidebar on (single-post) pages" Done.
How to use the empty space left and right of a post?
wordpress
My image galleries are showing only one thumbnail in the post the gallery sits in. http://themeforward.com/demo2/2013/03/08/image-gallery/ My single.php markup can be found here: http://snippi.com/s/akm5jb7 Additionally, previous_image_link and next_image_link are not displaying when the image is clicked (these would l...
It ended up being a problem with a code to pull a custom number of posts via an options panel.
Gallery Only Displaying One Thumbnail
wordpress
i have searched &amp; searched for an explenation and have found some answers that seem to be working for other people on this topics but i havent been able to get working. This is my "form" <code> &lt;div id="uploadPatternForm"&gt; &lt;div class="rightCol fleft w30 ml2"&gt; &lt;h4&gt;&lt;?php _e('Your Info', 'sagive')...
You get just the file names because you are not uploading the files. Uploading files using AJAX is currently not that easy. Newer browsers implement the <code> FormData </code> interface, but for older browsers you're stuck with some kind of flash uploader, like PlUpload for example. I suggest you use PlUpload because ...
insert post & Upload post thumbnail from the front end using ajax
wordpress
I have a custom image size at 200x150 that works fine in a plugin I'm working on. Uploading new files is no problem but when I edit an image, the default image sizes get regenerated but my custom size does not. Is there a way to force the regeneration programatically in a filter or something?
To regenerate custom image size when image is edited in image editor , You have to add following options in wp_options table using update_option function along with add_image_size. Example : <code> $img_size_name = 'custom-size'; // The new image size name. if ( function_exists( 'add_theme_support' ) ) add_image_size($...
Custom image size not regenerating when image editted
wordpress
I want to create a form that I can use a shortcode to insert into my site. It would be really nice if I could create the HTML part in a seperate file and then insert it with a PHP shortcode (to seperate the logic of the page from the mechanics of making it into a shortcode). How could I do this? -- Update -- This is wh...
Something I forgot in my previous comment was that shortcodes return content, both the suggested <code> include </code> and my alternative <code> get_template_part </code> will directly output the content (which is what you are seeing with the content appearing at the top of your page instead of where the shortcode is ...
Return HTML Template Page with PHP Function
wordpress
I come with a basic question but I can not solve, I think that will be easy for you. I would like, if I have 2 or more post on loop, show the entire loop. I tried the following: <code> &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $portfolio = new WP_Query(array('post_type' =&gt; 'project', '...
If you want to check the number of posts on each page, you can use the <code> found_posts </code> method of <code> WP_Query </code> : <code> &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $portfolio = new WP_Query(array('post_type' =&gt; 'project', 'posts_per_page' =&gt; 12, 'paged' =&gt; $pag...
Noob Loop Question
wordpress
I've been using the <code> nav_menu_css_class </code> filter in one of my plugins, implemented as: <code> add_filter( 'nav_menu_css_class', 'wbwcrf_nav_menu_css_class', 10, 3 ); function wbwcrf_nav_menu_css_class( $classes, $item, $args ) { /* snip */ return $classes; } </code> The filter clearly has 3 arguments in the...
I can confirm that this filter applied with 3 parameters as you mentioned in your snippet. The warning is very strange and shouldn't appear if WordPress core wan't hacked. The best practice for this case is to request parameters, which are required by your hook. So if you don't use <code> $args </code> , so don't reque...
Does the 'nav_menu_css_class' filter accept 2 or 3 arguments?
wordpress
I am creating a plugin which will also have a few addons. I am adding settings tabs for the addons, but I want to make a conditional check in the main plugin to prevent those tabs from showing if the addon plugin is not active. There is the function is_plugin_active() which can be used easily for this check, but what i...
There is the function is_plugin_active() which can be used easily for this check, but what if the user decides to change the folder name of the plugin? Simply put, you're doing it wrong. If you're making extensions for a plugin, then you should provide hooks in the "parent" plugin for those addons to hook into and chan...
Testing for addon plugin activated
wordpress
I am trying to make a custom sidebar for my posts in certain categories. It will look something like this. My category structure looks like this: Parent 1 Child 1 Sub Child 1 Sub Child 2 Child 1 Sub Child 1 Sub Child 2 Parent 2 What I want to do is to display all posts under Sub Child 1 and 2. I will be more specific, ...
I guess you could take a big step using <code> wp_list_categories() </code> with a <code> walker </code> to add a additional Unordered List to every item. The code : <code> $cat_id = get_query_var( 'cat' ); $subcats = get_categories( 'child_of=' . $cat_id ); // child categories class Cat_Walker extends Walker_Category ...
Display all posts under child sub category in sidebar on post page?
wordpress
I've simplified a problem of saving custom metaboxes on update and still can't get the box to save the custom-field input to the database. This is the call from <code> functions.php </code> to an external file <code> /metaboxes/home-meta-new.php </code> : <code> // Loading Home Page Meta Box Code from External .php fil...
When you do that <code> include </code> , you are trying to add the <code> save_post </code> hook inside the <code> add_meta_boxes_$post_type </code> hook. It should be independent. <code> add_action( 'add_meta_boxes_page','load_home_meta' ); add_action( 'save_post', 'save_home_meta' ); // Declare all callback function...
Custom Metabox Not Saving
wordpress
I'm writing my first twenty twelve child theme and came across (what I think) is a strange quirk. I modified front-page.php to have a slider using sliderjs, afterwards I decided I did not want to use this as a front page template, so I'd much prefer to call it something else for a different page. To my surprise, the mo...
I had the exact same problem and finally figured it out. You have to go into <code> functions.php </code> line 390 - <code> if ( is_page_template( 'page-templates/front-page.php' ) ) { </code> copy and paste this section of code and rename it to the file name you have chosen for your template. Then you have to alter al...
Is the front-page.php template reserved in wordpress twenty twelve theme?
wordpress
I now have this function that works well : <code> function wpPartValidate_settings( $input ) { if ( check_admin_referer( 'wpPart_nonce_field', 'wpPart_nonce_verify_adm' ) ) { // Create our array for storing the validated options $output = array(); foreach( $input as $key =&gt; $value ) { // Check to see if the current ...
First of all I would recommend you to rename your function to <code> wpPartSanitize_settings </code> , because this function doesn't validate anything. As it doesn't validate anything, then you aren't able to "inform" administrator that one input is invalid. Nevertheless, to create your hook for <code> wpPartValidate_s...
How to validate inputs with filter in register_setting callback
wordpress
I'm hoping this makes sense. When a user clicks on a post title I'm launching a modal overlay via fancybox, and feeding the associated post content via ajax. However I have a javascript call function that I need to run that is from the post that isn't running when the content is pulled. I have a guess the it has someth...
You need to apply any javascript after the content is loaded. See the Callbacks tab in documentation . <code> $(".fancybox").fancybox({ afterLoad: function(current, previous){ // initialize your js stuff } }); </code>
Load JavaScript from a post that's loading into Fancybox via ajax
wordpress
I am a theme author and the theme I made is used in a multisite environment. I have added the <code> custom_background </code> feature to this theme, with a default image and everything works as expected : the user can change the image and see the result live is the Theme Customizer before putting it online. Here is th...
I assume you mean " <code> get_theme_mod('background_image') </code> returns <code> false </code> " before I "save it once to activate it" If that is the case, <code> get_theme_mod </code> accepts a default parameter. Check the Codex: $name (string) (required) Theme modification name. <code> Default: None </code> $defa...
default custom background image not saved in database when creating a new site
wordpress
In the dashboard, I'm using a textarea to get user input. I'd like them to be able to use shortcodes anywhere in that textarea. Here's my current function: <code> function slp_getwelcome() { $slp_welcome = get_option('slp_welcome'); $slp_welcome_sc = do_shortcode( $slp_welcome ); return $slp_welcome_sc; } </code> This ...
You should be <code> return </code> ing $location from <code> get_location </code> , instead of <code> echo </code> ing it. Your function currently echos the location as soon as it runs, thereby outputting the result before the rest of the copy.
Do shortcode that is inserted in a textarea is not displaying properly
wordpress
nginx 1.2.7 + WP 3.5.1 + W3TC 0.9.2.8. Rewrite rules generated by the plugin simply don't work, server returns 404 after including them in nginx server config. Or maybe I'm doing something wrong? Here is my nginx.conf : <code> user www-data; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 1024; ...
Solved. Instead of <code> if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc") { set $w3tc_rewrite 0; } </code> should be <code> if (!-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc") { set $w3tc_rewrite 0; } </code> in W3 TC...
nginx + W3 Total Cache: rewrite rules issue
wordpress
I'm a newbie at modifying wooCommerce. I hope someone can help me with a problem i'm having while trying to make a minor change to the plugin to fit with a request from my client. I'm trying to modify WooCommerce to display the category name for each product. I want the category name to be shown above the product image...
The product title is added to the <code> woocommerce_single_product_summary </code> hook at priority 5, so you'll want to add to the same hook with a lower (earlier) priority. You'd add this to your theme's functions.php file. I presume when you say "category" you mean the WooCommerce product category, so this should r...
WooCommerce - how to display product category above product?
wordpress
I have a page template with a custom query: <code> &lt;? $filter = explode(' ', $_GET['filter']); // "page/?filter=taxonomy+term" $paged = get_query_var('paged') ? get_query_var('paged') : 1; $query = new WP_Query(array( 'post_type' =&gt; 'articles', 'paged' =&gt; $paged, 'tax_query' =&gt; array( array( 'taxonomy' =&gt...
You can't set query parameters after the query happens, set them before you make the query- <code> $args = array( 'post_type' =&gt; 'articles', 'paged' =&gt; $paged, ); if( some condition ) $args['tax_query'] = array( your tax params ); $query = new WP_Query( $args ); </code>
Set tax_query conditionally with new WP_Query
wordpress
Looking for a way to include custom fields in the output of WP_Query. I am managing a site where nearly every post type has a lot of custom fields defined and it would be much nicer not to have to run get_post_custom in almost every loop.
You may want to hook somewhere in the gazillion hooks available in <code> wp-includes/query.php </code> . I would suggest something like this: <code> function my_always_get_post_custom( $posts ) { for ( $i = 0; $i &lt; count($posts); $i++ ) { $custom_fields = get_post_custom( $posts[$i]-&gt;ID ); $posts[$i]-&gt;custom_...
Any way to include custom fields in WP_Query results?
wordpress
When using w3.org's validation tool Unicorn I get the following error/warning: URI: http://energyshop.se/hem/feed/ This feed does not validate. After looking into my source its there crystal clear in the <code> &lt;head&gt;: &lt;link rel="alternate" type="application/rss+xml" title="energyshop.se &amp;raquo; Hem kommen...
If we look at the file <code> /wp-includes/default-filters.php </code> we can find these two lines in there <code> add_action( 'wp_head', 'feed_links', 2 ); add_action( 'wp_head', 'feed_links_extra', 3 ); </code> so if we want to remove these actions, we can do it with these two lines in <code> functions.php </code> : ...
How do I edit wp_head and/or functions.php to remove rss-feed which isnt used and dont validate?
wordpress
I'm trying to create a shortcode to insert the Pinterest button with variables manually in posts. This is the code I've arrived at after reading various posts and grabbing the code from Pinterest. I haven't tested it yet. I wondered whether someone would kindly check for any obvious errors or problems? Secondly, I wond...
If you were to enable debugging and test the code (not sure why you are reluctant to do that), you would see that there are problems with the code. Your array elements need to be separated by commas and PHP variables begin with <code> $ </code> . What you have won't work as is. That kind of pure PHP code review is off-...
Shortcode with multiple variables
wordpress
In my wordpress site, I have inside the loop of single.php , a select tag in which the options are the posts of the current category returned via a custom query. On changing selected option, I have many javascript functions that are working well, but the last function among them (function f_next-previous), doesnt seem ...
I found it First, I want to note that the approach I mentionned in my question is bad according to almost tutorials talking about AJAX in wordpress. So I decided to change the approach and use the built-in AJAX of Wordpress. In other words, the best way for my situation is to use the wp-admin/admin-ajax.php. AJAX reque...
Dynamically changing navigation links (next and previous) via AJAX
wordpress
I am looking to call a new javascript function only after a new comment has been made by a user. Specifically, I want to include new javascript on the resulting page of the page reload after submitting the new comment form on a blog post. Does anyone know how to do this? My end goal is that I want to make a call using ...
I am not so clear where exactly you would want to "inject" this JS . <code> "After a new comment has been made" </code> , in WP terms and php workflow, can mean several things . (for example when the $POST request is made , when the action is triggered ,when it is getting checked, sanitized , when it is inserted to the...
Including new Javascript only after a comment is made
wordpress
I'm trying to do a custo slideshow, but I have problems with query the posts. I have defined a custom post type "slider" and a custom taxonomy "slideshow": custom post type: <code> function wms_slider_init() { $labels = array( 'name' =&gt; 'Slider', 'singular_name' =&gt; 'Slider', 'add_new' =&gt; 'Add Slider', 'add_new...
You should access global variables in php using global keyword.It makes variable( or object, array) visible inside current function we are dealing with. In function wms_output_home_slides you are using $post global variable directly instead access it using global keyword as following. <code> function wms_output_home_sl...
Query custom posts from custom taxonomy
wordpress
I would like to know how to perform a proper validation with the <code> register_setting() </code> callback function. Here is a sample part of my code I want to work with: <code> register_setting( 'wpPart_options', 'wpPart_options', array( &amp;$this, 'wpPartValidate_settings' ) ); </code> <code> $this </code> is an ar...
Personally I'd do it the same way, since it seems to be the only point where you can examine user input and validate it. Also, heavily borrowing from code sample in this excellent article : <code> function wpPartValidate_settings( $input ) { if ( check_admin_referer( 'wpPart_nonce_field', 'wpPart_nonce_verify_adm' ) ) ...
How to validate register settings array
wordpress
I am building a classifieds website and am using Wordpress for the functionality of user accounts, Paypal integration, custom taxonomies and of course super flexible custom post types for the listings. I would like to be able to map a subdomain to a particular sub-site. For example: australia.somesite.com or brisbane.s...
Sort of a vague question, but I think I understand what you're getting at. You'd need to use a Wordpress Multisite installation, which will effectively create localized blogs on a subdomain (brisbane.example.com, perth.example.com). Using a single site Wordpress installation to do this is possible, using CNAME mapping ...
Mapping Subdomains in Wordpress to give the appearance of a localised site, best approach?
wordpress
I am trying to create a menu, with sub-pages and sub-sub-pages of a current page. I want the menu to work as a dropdown, where the sub-sub-pages for a sub-pages are shown when the user clicks the sub-page, and hidden again if the user clicks on the sub-page a second time. So it is important that the sub-pages in the me...
You can use <code> get_page_children </code> function to retrieve all sub pages <code> $the_query = new WP_Query( array( 'post_type' =&gt; 'page', 'posts_per_page' =&gt; -1 ) ); $children = get_page_children( get_the_ID(), $the_query-&gt;query() ); if ( !empty( $children ) ) { foreach ( $children as $child ) { // rende...
Show menu on page with all sub-pages and sub-sub-pages of that page
wordpress
I'm not sure whether this question belongs here but I don't know where else to ask it : do WordPress designers/developers usually create a dashboard theme thumbnail when they completed the WP theme for their client? If so, do they put their own logo on it or a screenshot of the home page?
Thats entirely up to to you. I generally create a theme thumbnail from the PSD file, or, when the theme changes a lot between designing and developing, I tend to create one from a screenshot. Look at the Themes Directory , you can see some of the developers actually don't use a screenshot but some other image. If you w...
Theme thumbnail in dashboard
wordpress
I still haven't figured this out yet. Is this the right way? I tried <code> $_POST['content'] = "nothing" </code> and <code> $_POST['content'] = 0 </code> neither work for me. I'm using following way <code> function changeContent() { $_POST['content'] = "nothing"; } add_action('publish_post', 'changeContent'); </code> ...
You might check out the <code> content_edit_pre </code> filter. Your example would then look like this: <code> function wpse89725_pre_edit_content( $content, $post_id ) { $content = "nothing"; return $content; } add_filter( 'content_edit_pre', 'wpse89725_pre_edit_content', 10, 2 ); </code> You can read more about this ...
How to modify post content?
wordpress
I am building a site for a friend, the site has launched, now he tells me he wants his site name to appear green everywhere it appears on the website. Immediately, I thought of the plugin SEO Smart Links , which automatically links a string of text. Is there anything like this for applying styles or classes to a string...
If it's purely for setting the style of the text you may want to use JavaScript/jQuery instead. Here's a quick sample that would replace all instances of "ipsum" with <code> &lt;span class="red"&gt;ipsum&lt;/span&gt; </code> And the full code: <code> // Find text in descendents of an element, in reverse document order ...
How to add style to a string of text throughout WordPress website?
wordpress
I have a function that expires posts on a date, and adds a check to the database. Now, I'd like the ability to "recycle" those posts with new expiration date, but in order to do this, I need to erase the _expiration_date_processed entry. Is the function below the best way to achieve this, especially in the case where t...
Nevermind, I was complicating this whole process because I wasn't thinking about just using get_post_meta(). <code> add_action('draft_to_publish','gcpl_draft_to_published'); function gcpl_draft_to_published($post){ $exp_processed = get_post_meta($post-&gt;ID, '_expiration-date-processed', true); // check if the custom ...
Using $wpdb to update current post
wordpress
I'm new to WordPress. I started the site as good with folder name <code> wordpress </code> . After I changed the folder name from <code> wordpress </code> to <code> test </code> . And also change the siteurl from <code> http://localhost/wordpress </code> to <code> http://localhost/test </code> in wp_options table. And ...
After changing siteurl, Go to admin panel and update permalink structure once and check.It will start working with new folder name. Hope it helps
problem with guid, when i change the folder name
wordpress
I need to include the path to my theme file within a javascript file. How would I go about this? I have already tried: <code> var templateUrl = "&lt;?php get_stylesheet_directory_uri(); ?&gt;"; function LightboxOptions() { this.fileLoadingImage = "'"+templateUrl+"/img/loading.gif'"; this.fileCloseImage = "'"+templateUr...
What you're looking for is wp_localize_script function. You use it like this when enqueing script <code> wp_register_script( 'my-script', 'myscript_url' ); wp_enqueue_script( 'my-script' ); $translation_array = array( 'templateUrl' =&gt; get_stylesheet_directory_uri() ); //after wp_enqueue_script wp_localize_script( 'm...
theme path in javascript file
wordpress
I have post name in Thai which uses <code> UTF-8 </code> character. Many of them encode into super long in ASCII e.g. วิธีการหลีกเลี่ยงข้อผิดพลาดทั้ง-8-ในชีวิตการแต่งงาน I've changed the type of "post_name" using phpMyAdmin to <code> VARCHAR(1000) </code> and collation to <code> utf8_unicode_ci </code> . However, in my...
It happens because when you save a post, WordPress calls <code> sanitize_title </code> function to sanitize your title. This function applies <code> sanitize_title </code> filter. One of core hooks for <code> sanitize_title </code> filter is <code> sanitize_title_with_dashes </code> function, which checks title on utf8...
How to increase the character limit for post name of 200?
wordpress
I was wondering how i can handle a shortcode function directly? At the moment i have created a shortcode which works OK. The shortcode function outputs a image. Now in functions.php i have another function which needs the output image. I am using the do_shortcode and it works. <code> $image = do_shortcode('[route_thumb...
Shortcode handler function receives two arguments array <code> $attr </code> and string <code> $content </code> . So to pass attributes to shortcode handler function, just pass it as array: <code> $image = route_thumb_function( array( 'id' =&gt; $post_id ) ); </code>
How to handle a shortcode function directly?
wordpress
I am unable to get this insert to db function to work using ajax and a form. When I execute this, I receive a blank alert box on success. HTML <code> &lt;div id="rsvpContent"&gt; &lt;form id="Attendevent" action=""&gt; &lt;input id="attend" name="attend" type="checkbox" value="yes" /&gt;&lt;label for="attent"&gt;Yes, I...
You are serializing your form data before posting it to your PHP function, but you do not unserialize it at the other end. Therefore your check for <code> $_POST['attend'] == 'yes' </code> will always fail. Try the following (untested). <code> function eventAttend() { $fields = array( ); parse_str( $_POST['data'], $fie...
Submit form to db
wordpress
I have used a plugin called Amazon product in a post . It works okay with posts type. It adds custom fields in the posts page. But, I have made another custom post type called products. It does not work with that. I want the custom field appear in Products post type. I have used few suggestions. Adding plugin in custom...
Suresh what is the custom post type you want to hook into? You need to make sure you change the $custom_post_type = 'put-post-type-here'; line to be the actual custom post type slug you want to hook it into. Then, I would suggest adding the function to the functions.php. And try it this way: <code> add_action('admin_me...
How to add plugin custom field to custom post type?
wordpress
I'm using the below function for wp_link_pages. It can be viewed in use here. I would like to add a class to the previous link and a class to the next link so they can be styled individually. I'm not a pro at WP functions and I'm curious what the proper way to do this is. I can always simply echo divs around each, but ...
First, I would add a string formatting placeholder to 'link_before', like so... <code> $args['link_before'] = '&lt;span class="classlinks %s"&gt;'; </code> Next, I would use sprintf() to insert an appropriate class for the appropriate link (let's assume the classes will be 'link-before' and 'link-after', respectively)....
Add Unique Classes to Next and Previous in WP_LINK_PAGES
wordpress
I have a template file which shows the posts of a category called downloads. for each posts i have attached a pdf file. I have given a link to download the pdf file on the page. But when i click the download link it goes to the post page and from there i have to click to download the file. Is there any way to directly ...
Add the PDF attachment ID as a custom field value, for example <code> attached_pdf_id </code> . Get the URL using <code> wp_get_attachment_url() </code> : <code> &lt;?php if ( is_user_logged_in() ) { $pdf_link = wp_get_attachment_url( get_post_meta( get_the_ID(), 'attached_pdf_id', true ) ); if ( $pdf_link ) { ?&gt;&lt...
wp_get_attachment_url not working
wordpress
I am creating a plugin, where the user can create forms with an unlimited amount of fields. I would like to store each field the user creates as an array in a post meta field. What would the code look like for this please? (This is the first plugin i've ever created). @Wyck previously touched on this topic below, but d...
WordPress automatically serializes/unserializes the data when it's stored and retrieved, all you need to do is pass a php array as your data and you'll get the same array back when you <code> get_post_meta </code> . <code> $data = array( 'label' =&gt; 'something', 'desc' =&gt; 'someval', 'id' =&gt; 'someval', 'type' =&...
How to store post meta in an array
wordpress
Im using following code for getting most populer post with thumbnail.I have a custom post type taxonomy (Talks). Custom post types(video) have 6 category. But my code not working. It just getting 1 post.But i have 10 post. How can i fix it? <code> &lt;?php $args = array( 'post_type' =&gt; 'video', 'showposts' =&gt; 10,...
Brain helped me.. I have installed already WP-PostViews Plugin I just changed following line on my code and it worked. Thanks for all answers and suggestion. <code> 'meta_key' =&gt; 'views' </code>
Most viewed post of custom post type
wordpress
I found an interesting concepts of adding an additional option to the "General Options" in Wordpress. <code> /** * Custom Theme Settings * see http://digwp.com/2009/09/global-custom-fields-take-two/ */ add_action('admin_menu', 'add_gcf_interface'); function add_gcf_interface() { add_options_page('Other', 'Other', '8', ...
You can create a custom filter using filter functions of Plugin API. I have changed you code as following to create and use custom filter. <code> function add_gcf_interface() { add_options_page('Other', 'Other', '8', 'functions', 'otherGlobalOptions'); } function otherGlobalOptions() { ?&gt; &lt;div class='wrap'&gt; &l...
Custom Theme Fields in Settings Menu - apply filters to one of those fields?
wordpress
The WordPress SEO plugin by Yoast allows users to add SEO titles and meta descriptions to taxonomy term archive pages. These are then used in the head of the document. I´m trying to display the SEO title of taxonomy terms as an H1 in my taxonomy archive template. To do this in a post, post type or page is easy: <code> ...
Get Archive SEO titles If you defined a Custom Post Type archive title you can get that by: <code> $titles = get_option( 'wpseo_titles' ); $title = $titles['title-ptarchive-POST_TYPE']; echo apply_filters( 'the_title', $title ); </code> Remember to replace <code> POST_TYPE </code> by your own Custom Post Type. To displ...
Display Yoast WordPress SEO title in archive template
wordpress
I am creating a plugin. That enables users to create forms, &amp; display these with shortcodes on a site. When creating a form (using custom post types), users will be able to add additional form fields with meta boxes. My question: When a user creates a form (via custom post type), how do I store the field type so th...
Store each field the user creates as an array in a post meta field, the array would contain the name and a reference to the field type. You could also store additional data within the array, like if it's required and the type of validation to apply.
Creating shortcodes with user created forms
wordpress
i need help in httaccess rewrite of a wordpress site. i have url like below http://thewhiterabbit.dk/beta/steder-detail/?id=floos i want it to be like http://thewhiterabbit.dk/beta/steder-detail/floos i have developed using id=floos, now instead of redeveloping all thing i just want a rule to change the url any help wi...
At first, you shouldn't use .htaccess directly when working with WordPress. WordPress has powerful rewrite API allowing you to do the stuff from plugins or theme's functions.php If you need the id=floos on more than one page, consider using rewrite endpoints : <code> function makeplugins_add_json_endpoint() { add_rewri...
ow to change cutsom page url of wordpress site using htaccess
wordpress
Basically i have front end form which store the notes and tags of post. And every user who logged in can store there own notes and tags. But i want when he view the notes and tags he can only see here own notes and tags not all the notes and tags of every one. For example there are 100 post there. Every user have an op...
There are various ways to achieve this you can either generate metakey value for update_post_meta in such a way that it will contain user id. <code> //Example : global $user_ID,$post_ID; // Store the values update_post_meta($post_ID, 'meta_key'.$user_ID, '$meta_value'); // Get the values $meta_values = get_post_meta($p...
How we can get "get_post_meta" of specific user who added it
wordpress
The latest version of jquery ui core fixes a bug that's on my site. The problem is that Wordpress comes with an earlier version. How do I override the default jquery ui core? One solution I've found is to edit the script-loader.php file in wordpress includes folder but I don't want to touch the WordPress core unless I ...
Add the following code in functions.php file of your theme that will remove default jquery ui core and will add your provided latest jquery ui core file from your theme. <code> function my_scripts_method() { if(!is_admin()){ wp_deregister_script( 'jquery-ui-core' ); wp_enqueue_script('jquery-ui-core', get_stylesheet_di...
Override default jquery ui library with newer version
wordpress
I am looking to use the gform_column_input_content filter to make a repeatable file upload element. The filter modifies the HTML content of the list field column input tag. The following code provided from the docs shows how to replace the default text input with a textarea input. <code> &lt;?php add_filter("gform_colu...
The following provides you with a file upload: <code> add_filter("gform_column_input_content_21_9_3", "change_column3_content", 10, 6); function change_column3_content($input, $input_info, $field, $text, $value, $form_id) { $input_field_name = 'input_' . $field["id"] . '[]'; $tabindex = GFCommon::get_tabindex(); $new_i...
Gravity Forms - Repeatable "File Upload" field using "gform_column_input_content" filter
wordpress
What I want to do seems to be simple but I can't get around it. I'd like to get the latest post that has an image attachment. A little help would be appreciated. Thanks Lita
This is a tricky one. If you wanted to get the latest image attachment and display the post associated with it, you could use: <code> $attachments = get_posts('post_type=attachment'); $first_attachment_post = get_post($attachments[0]-&gt;post_parent); </code> To get the latest post, but only if it has an attachment, I ...
Fetch the latest post with attachment image
wordpress
I have build a simplified version of wordpress admin without all the features and stuff, only posting some specific custom post types and pages. This simplified version addresses a specific role on my normal wordpress operation (since admin is such a fuss to customize), but it lacks some things, such as using the plugi...
Since the last time, I was able to make my own private messaging system. I do have some other questions which I will post in another "ask question" segment.
Private messaging plugins + custom admin
wordpress
So, I'm not sure if this is possible, but is it possible to add custom Capabilities? So, I've written a group message application, that ties in with Wordpress. I only want certain members (set via options that I just asked about) to be able to send out such messages. I'd like to add a capability for, say "group_message...
I just happened to provide a short example of role capability (exaplanation and code). In your case, however, you want to add the capability to particular users - not roles. The following code may be a starting point for what you want to do: &gt;&gt;&gt; Setting it up <code> // The IDs of the `privileged users` $users ...
Adding Custom Capabilites
wordpress
I need to load a meta box for editors to choose the parent post first before editing. But dont see the wide meta box i expect and the normal edit page just loads: This is the code at the begining of wp-admin/post-new.php : <code> if ( $post_type == 'news' &amp;&amp; !isset($_GET['parent_id']) ): //checking if parent_id...
You shouldn't ever be modifying any of the WordPress core files, your changes will be lost as soon as the next WordPress update is released. The easiest way to do this would be with Advanced Custom Fields, create a "relationship" custom field type and make it a required field. That way the user can't save the post with...
Loading one meta box only on post-new.php with a forward link
wordpress
I'm trying to convert a json string back into an array in wordpress. Here is the json string that I'm getting back from the database: <code> [ { "item_title": "Kindle Fire HD 7\", Dolby Audio, Dual-Band Wi-Fi, 16 GB - Includes Special Offers", "item_url": "http://my.dev/tester/wordpress/wp-content/ecom-plugin-redirects...
I tried to parse your JSON into this and got an error that you have bad escaped characters (backslash must be escaped). Taking into account stackexchange-url ("Vinod Dalvi's comment"), the definition of <code> json_encode </code> in WordPress is wrapped by <code> function_exists() </code> . I guess if you have PHP vers...
json_decode does not work on Wordpress
wordpress
I would like to add one line to a wp core file. Basically on the 'edit.php' page, just right above <code> &lt;?php include('./admin-footer.php'); </code> I would like to add an php include statement... <code> include('./custom-file.php'); </code> The custom-file is located inside a plugin, not a theme... so if I write ...
There is zero reason to do this. Why would you need your include in <code> edit.php </code> ? Just include it in your plugin. If for some reason you need to hook into the <code> edit.php </code> page (hard to tell what you're doing), you can use, <code> add_action( 'load-edit.php', 'your_function' ); </code>
Possible to add a statement to a core file?
wordpress
Been hunting for a while and I can't figure out how to use <code> get_custom_header </code> to get the alt text associated with the media file, so that I can add photo credits to the headers on my site. Am I missing something? Code to add header image is: <code> &lt;img src="&lt;?php header_image(); ?&gt;" height="&lt;...
Use this for the <code> alt="" </code> attribute on the custom header <code> &lt;img&gt; </code> tag … <code> alt="&lt;?php $attachment_id = get_custom_header()-&gt;attachment_id; $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); if ( count( $alt ) ) echo $alt; ?&gt;" /&gt; </code> … and then ju...
Add credit to get_custom_header in alt
wordpress
I am in the middle of creating a plugin and everything works fine with the AJAX calls but one question I can't seem to find the answer to is about best practise. I route the AJAX calls through <code> /wp-admin/admin-ajax.php </code> and have my php functions in the theme <code> functions.php </code> script. However, I'...
WordPress AJAX best practices are following: Use <code> wp_localize_script </code> to declare JavaScript global variables; Use <code> admin-ajax.php </code> script to handle all AJAX requests; Use nonces and check for permissions; Use jQuery Form plugin to submit forms. Read 5 tips for using AJAX in WordPress article f...
What are the Best Practises When Using AJAX in Plugin Development?
wordpress
I want to reset admin's meta value after login. It can be changed after login by admin via control panel, but I want to reset it after every login. I used this code but it's not working: <code> function reset_dismiss_message(){ update_user_meta( get_current_user_id(), 'tgmpa_dismissed_notice', false ); } add_action('wp...
<code> wp_login </code> action passes 2 arguments <code> $user_login </code> and <code> $user </code> . The second argument is the object of <code> WP_User </code> class, which you can use to get user id from: <code> function reset_dismiss_message( $user_login, $user ) { update_user_meta( $user-&gt;ID, 'tgmpa_dismissed...
I want to reset user's post meta after successfully login
wordpress
I have just got into using hooks and have now understand the beauty of them. I understand that I can hook into the following by using <code> add_filter('hook_name','my_hook_name', $variable); </code> <code> function a_function($variable){ return add_filter('hook_name', $variable); } </code> But what if your the functio...
You cannot hook in a function without a hook. If it returns a variable, you will have to use it as it is returned. And then, maybe, perform your operations on that.
Hook into a function without a hook?
wordpress
I want to restrict access to my wordpress site to allow registered users only. I have tried the following plugins: Require-login Authenticator WP-lock All of them have the same problem: After seeing the login page, you can easily retype the URL in the browser address bar to bypass the login screen and access the home p...
It seems to me that all you should need is this: <code> function force_login_wpse_89581() { if (!is_user_logged_in()) wp_safe_redirect(wp_login_url()); } add_action('template_redirect','force_login_wpse_89581'); </code> That should force users to the login page except for users who have already logged in. I don't know ...
force login loophole
wordpress
I accidentally deleted post that related to certain users in wordpress because I deleted user. How can I restore those posts? Thank you!
Go to Pages/Post--> All Pages/Posts--> Click Trash, then restore them....
How to restore deleted post related with deleted users
wordpress
Good day, everyone: I want to make wordpress to add the user's id number behind the ref's link string, so that, for example <code> &lt;div class="toolsbutton"&gt; &lt;a href="http://mysite.com/mysite/page-"&gt;go this page&lt;/a&gt; &lt;/div&gt; </code> above code will be turning in to a link if the user id is 113 who ...
I guess maybe <code> wp_get_current_user(); </code> is what your looking for. Something like this... <code> &lt;?php $current_user = wp_get_current_user(); ?&gt; &lt;a href="http://mysite.com/mysite/page-&lt;?php echo $current_user-&gt;ID; ?&gt;"&gt;go this page&lt;/a&gt; </code> http://codex.wordpress.org/Function_Ref...
Adding a user's ID behind the tag ref link address
wordpress
I have created a category "Book" with a sub category "comics", to check how wordpress is maintaining the hierarchy structure. When i check the table "wp_term_taxonomy", I found that such term with a parent has "parent" field populated . As the term id and term_taxonomy_id have the same value for the parent "term name" ...
The <code> parent </code> column is the <code> term_id </code> of a parent term
Has parent field in the table wp_term_taxonomy has term_id or term_taxonomy_id
wordpress
What I am trying to accomplish is placing custom widget on an admin page (edit.php). I tried using these two functions: Places custom html right below &lt; body > (above all page content) <code> add_action( 'load-edit.php', 'your_function' ); function your_function() { include( plugin_dir_path( __FILE__ ) . 'quickpost/...
As far as I know you have 2 options. Using <code> admin_footer </code> or <code> load-edit.php </code> and position with <code> absolute </code> or <code> fixed </code> , or use JavaScript. If you creating a completely new posts screen (not a default posts, pages, etc), you can extend <code> WP_List_Table </code> class...
How to add custom widget above admin_footer
wordpress
I am using plugin like to read http://wordpress.org/extend/plugins/like-to-keep-reading/ problem is its using opening and closing shortcodes,when I embed them to my site http://vijaykudal.info only opening short codes displayed,can you please help me? PS:-tried with different themes as well
To put shortcode within a PHP template, use do_shortcode(); <code> &lt;?php echo do_shortcode( '[like_to_read]The text that is hidden from the user.[/like_to_read]' ); ?&gt; </code> Edit: <code> &lt;?php echo do_shortcode( '[like_to_read]' . get_the_content() . '[/like_to_read]' ); ?&gt; </code>
using shortcodes in theme content
wordpress