question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
In my theme, I am using some PHP to display custom field content. It checks if the fields are empty before displaying the content, because the_meta was showing titles for empty fields. <code> &lt;div class="customfield-box"&gt; &lt;?php $ck = get_post_custom_keys($post_id); //Array foreach ($ck as $k) { if (substr ($k,...
Something like this: <code> $ck = get_post_custom_keys($post_id); //Array // drop keys starting with '_' $ck = array_filter($ck, function($key){ return strpos($key, '_') !== 0; }); // store your root keys here $data = array(); foreach($ck as $k){ $cv = get_post_custom_values($k, $post_id ); //Array // drop empty values...
Custom fields PHP foreach loop
wordpress
I need to display on some specific pages some selected user meta data (not all), for some users. On the Wordpress Codex page for the <code> get_user_meta() </code> function we have this example (user_id = 9): <code> &lt;?php $all_meta_for_user = get_user_meta( 9 ); print_r( $all_meta_for_user ); ?&gt; </code> The resul...
Here is the simplest shortcode that will do the job for you <code> add_shortcode('USER_META', 'user_meta_shortcode_handler'); /** * User Meta Shortcode handler * usage: [USER_META user_id=1 meta="first_name"] * @param array $atts * @param string $content * @return stirng */ function user_meta_shortcode_handler($atts,$c...
How to display some selected user meta data on a specific page with a shortcode?
wordpress
I'm trying to write a plugin that creates a page if a box is checked (value 1) and if the post id doesn't already exist. If the post id does already exist, then I want to update the post with whatever changes have been made. I have the creating post (as page) part working just fine. However, when I try to do run the wp...
The first argument of <code> array_merge </code> is the array of old values pulled from the original post, not your new values, so I'd guess you're passing an invalid post ID. In your array of new values, I think you want to set post ID to <code> $page_check_404-&gt;ID </code> , not <code> $ss_404_post_id </code> .
Problem with wp_update_post
wordpress
I have an audio player than uses the following syntax to display its player: <code> [audio src="http://somedomain.com/wp-content/uploads/2013/01/songtitle.mp3"] </code> The thing is, I'm pretty sure I can show the user how to copy the url and paste it in the post, but how can I search the content for a <code> .mp3 </co...
Filter <code> the_content </code> ond/or <code> the_excerpt </code> and replace audio URLs that are not an attribute value already. Example: <code> add_filter( 'the_content', 'wpse_82336_audio_url_to_shortcode', 1 ); add_filter( 'the_excerpt', 'wpse_82336_audio_url_to_shortcode', 1 ); function wpse_82336_audio_url_to_s...
Audio tags around Mp3 URL in content
wordpress
I am very new to WordPress. I am trying to display a login form in the header section of my website. However, when I look at all of the files in my directory it is very overwhelming and I am afraid to touch anything. Does anyone know of any good tutorials on the topic or perhaps shed some light on the issue?
Create a template file within your child theme directory, let's say <code> login.php </code> . Put the login form inside this file: <code> &lt;form action="" method="post"&gt; &lt;div&gt; User name: &lt;input name="log" type="text" /&gt; &lt;/div&gt; &lt;div&gt; Password: &lt;input name="pwd" type="password" /&gt; &lt;...
Custom login form
wordpress
With the below two functions I can add a textarea custom user meta field named 'publications' to the user profile and save/update it: <code> add_action( 'show_user_profile', 'extra_user_profile_fields' ); add_action( 'edit_user_profile', 'extra_user_profile_fields' ); function extra_user_profile_fields( $user ) { ?&gt;...
Finally I adopted this the second solution: <code> /* Display the selected user meta data with a shortcode */ add_shortcode('user_meta', 'user_meta_shortcode_handler'); /* usage: [user_meta user_id=1] */ function user_meta_shortcode_handler($atts,$content=null){ ?&gt; &lt;?php echo '&lt;h3&gt;Publications&lt;/h3&gt;'; ...
Display user meta data from a textarea as a formated text
wordpress
I have a wordpress site with static page as the front page. I want to have <code> /blog </code> to display the recent posts. How can I do that? thanks.
Create a page with a custom page template , then create a custom WP_Query object to return your last posts. You can get something like: <code> &lt;?php /* Template Name: Blog Page */ get_header(); $args = array( 'post_type' =&gt; 'any', #all post types 'posts_per_page' =&gt; 10 #get 10 posts ); $query = new WP_Query( $...
Custom URL for all posts in Wordpress
wordpress
I recently tried to reorder the dashboard widgets by writing a plugin. I accomplished this: with the following code: <code> &lt;?php /* * Plugin Name: Custom Dashboard * Description: Custom dashboard for Avare sites. * Author: Avare * Version: 1.0 */ function sort_dashboard_widgets() { $left_column_widgets[] = 'dashboa...
Whoop, I figured it out. :) Although I figured it out before kaiser answered my question, I would still like to thank him for is clear and awesome answer. Below you'll find the code I wrote to reorder the dashboard widgets. <code> &lt;?php /** * Plugin Name: Custom Dashboard * Description: Custom dashboard for Avare si...
Reorder dashboard widgets
wordpress
So I'm just working for a client right now importing CSVs of products to WooCommerce. I've imported a lot of products so far using an existing plugin, but don't want to buy the CSV Product Import Suite for $99 to import product variations. So... Can anyone help me to answer one of the following two questions: Does anyo...
This one is not as extensive as the woo product but works very well and you can easily modify it. Good luck. By the way, today, and I don't know for how long, woo is having a 50% discount on their plugins. Just go to their site. Here's your plugin link https://github.com/dgrundel/woo-product-importer/blob/master/README...
How does WooCommerce store products / product variations? / Free Script to import product variations?
wordpress
Okay, so I'm creating a website and am in need of help for some custom meta fields for user profiles. Currently I have the following in my functions.php file: <code> //hooks add_action( 'show_user_profile', 'Add_user_fields' ); add_action( 'edit_user_profile', 'Add_user_fields' ); function Add_user_fields( $user ) { ?&...
You appear to be checking for variables that aren't set. You set <code> $selected </code> <code> $selected = get_the_author_meta( 'user_top', $user-&gt;ID ); </code> But then you check for something called <code> $topselected </code> <code> &lt;select name="user_top" id="user_top"&gt; &lt;option value="gotguns" &lt;?ph...
Using and saving custom dropdown boxes on user profiles
wordpress
I have following links in content.php and i want to display in specific page with condition. Any ideas or suggestions? Thanks. Home Director’s speech Projects Our Vision Volunteers Inquiry
You can either create a custom page template , or just add the code to your regular <code> page.php </code> : <code> if ( is_page( 'your-page-slug' ) ) { echo 'your links'; } </code>
How to display links in specific page
wordpress
Here is the situation: I have an automated script that upload attachments and link each attachment to a specific post. By mistake, the script run multiple times and I have the following More than one attachment post in the Media library for a single file (the different attachment posts have the same File URL). One of t...
<code> function get_attachment_files(){ $args = array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; -1, 'post_status' =&gt; null, 'post_parent' =&gt; 0 ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $post) { setup_postdata($post); wp_delete_post( $post-&gt;ID ); } } } add_action...
Remove duplicate attachments
wordpress
Below there's the Wordpress code found in post-template.php for the wp_link_pages() function - this function generates a page navigation for posts or pages having the content split into multiple pages. <code> function wp_link_pages($args = '') { $defaults = array( 'before' =&gt; '&lt;p&gt;' . __('Pages:'), 'after' =&gt...
Currently it is practically impossible. Need write your own version of the function. I did just so for my theme in development. There is a trac ticket requesting improvements to the function since it is inflexible, yet required for themes hosted in official repository.
Make wp_link_pages() suitable for Twitter Bootstrap markup
wordpress
Is there a filter hook which changes the number of available columns in gallery settings screen. I'm talking about the : <code> &lt;label class="setting"&gt; &lt;span&gt;&lt;?php _e('Columns'); ?&gt;&lt;/span&gt; &lt;select class="columns" name="columns" data-setting="columns"&gt; &lt;?php for ( $i = 1; $i &lt;= 9; $i+...
Short answer Simple as things sometimes are: No this is not possible. The whole part is hard coded. Long answer (not recommended to do so) You could maybe jump into the <code> esc_html </code> and <code> attribute_escape </code> filters and just return empty there *), but as those are pretty generic names and would pos...
Gallery Settings Change available Columns
wordpress
I am creating a theme that deletes some user roles that are not necessary and creates others. (It deletes author and contributor and renames subscriber). Everything works, but on theme deactivation, I want to readd all the roles I deleted. Do I have to manually go in and create the roles (author and contributor), manua...
Use a plugin to manage roles, stackexchange-url ("not a theme"). Roles are not for presentation. In your plugin use <code> register_activation_hook() </code> and <code> register_deactivation_hook() </code> to add or remove new roles. Do not remove built-in roles, other plugins may rely on their existence.
Reset Roles (or undo role changes on theme change)
wordpress
Problem : when I do www.example.com?cat=4 or choose category through custom menu or from category widget it shows only first page without navigation at the bottom, where it supposed to be. It's the same if I use index.php or category-slug.php as template. For test, when I do www.example.com?year=2012 it works. Also, ww...
I found a partial workaround. Since the query object in the index.php is the right one I transferred it using serialize to template of choice, in this case category-video.php. In index.php i put on top <code> &lt;?php $s = serialize($wp_query); file_put_contents('query',$s); ?&gt; </code> and in category-video.php I pu...
Page navigation doesn't show when query category
wordpress
I use Wordfence plugin which scans server side plugins with original plugin files to see if anything was modified by hacker/cracker. Today I got a warning and it shows these modifications on /w3-total-cache/lib/W3/Cache/File.php should I be worried? Last time I read there is a W3 exploit going around .
That security hole in W3 Total Cache was associated with data leaking through an exploit, and not explicitly with hackers changing code (that could happen afterwards, of course, but what you show isn't this). The exploit has been fixed so just make sure your plugin is up to date. If unsure, disable / delete the plugin,...
wordfence scan warning on W3 Total Cache
wordpress
We want user to register and then comment. So we, Checked the option of "Anyone can register" as true. Checked the option of "Users must be registered and logged in to comment" as true. Now, the problem is nothing shows up in a single post page below "Speak your Mind". Here is the snapshot of problem -> Here is the com...
I finally did the old school way of disabling all plugins and enabling them one by one as suggested by the Studiopress Support team and found out that 'Genesis Simple Comments' plugin was causing this problem. Nick, the author of the plugin said that it needs an update, so for now the issue is solved.
Log in link not showing, Comment Issue
wordpress
For me this is quite hard to do, but I guess that this could be easily done by an expert. :) Let's suppose I have a post, which is a custom post type <code> resources </code> , with the following data: Post Slug : beach Custom Fields : <code> dl1file </code> : bikini <code> dl1link </code> : assets/file1.zip <code> dl1...
The first step in making this work is to register your custom query var for the file via the <code> query_vars </code> filter. I've named it <code> wpa82328_file </code> , but you can change this to something more meaningful to you. <code> file </code> is a bit generic though, so you'll want to prefix it with something...
How to create download links based on Custom Fields with Rewrite API
wordpress
I am looking for a guide or tool for inserting bootstrap in to underscores theme. Booststrap is a CSS framework and Underscores theme is starter theme with ultra-minimal CSS.
I created a theme for this purpose. More details: http://theme.firmasite.com/
A guide or tool for inserting bootstrap in underscores theme?
wordpress
How can i retrive the actor birthday by Date. How i add the date, i have a custom field with Calendar. Now is 20th ... how can i retrive the Actor By this day I try this but it wont work <code> &lt;?php // Get today's date in the right format $todaysDate = date('md'); ?&gt; &lt;?php $loop = new WP_Query( array( 'post_t...
For this to work you need the date stored in the database to match the <code> $todaysDate </code> and it probably doesn't. If I am reading your somewhat confusing question correctly then you are storing dates like <code> 20th Jan 2013 </code> but you are matching it against a date that looks like <code> 0120 </code> (J...
How can i get the actor birthday by date?
wordpress
I'm not sure that my title accurately explains what I'm trying to do, but it's the best way I could think of to explain what I'm attempting to do. I'm writing my first Wordpress plugin, and while it's been a huge learning experience so far, I've found myself stuck. Basically, the plugin adds a shortcode, <code> [routes...
If you want to do this with options, save the routes as an array rather than individual options, or save the number of routes in an option so you can dynamically create and fetch them by building the option names based on the number you save. However , rather than saving this stuff in options, I would make a route cust...
Can I dynamically create duplicate fields with the Settings API?
wordpress
I know that I can visit <code> /wp-admin/options.php </code> on a single install (or on a sub-site on a multisite install), and it will give me a formatted list of all of the options in the site's <code> {prefix}opitions </code> database table. How can I achieve a similar list in the network dashboard for the <code> {p...
There is no function for that. But you can use a custom SQL query like this … <code> SELECT meta_key, meta_value FROM $wpdb-&gt;sitemeta WHERE site_id = $wpdb-&gt;siteid AND `meta_key` NOT LIKE '_site_transient%' ORDER BY meta_key </code> … to get all non-transient options. Basic example: <code> /** * Plugin Name: T5 M...
Listing of all site options in dashboard
wordpress
I am using custom user roles which I create and assign by using a plugin. I was wondering how I could retrieve the user's role and store it in a PHP variable. What I am trying to achieve is something like this: Let's say I created 3 custom user roles: <code> role_apple </code> , <code> role_banana </code> and <code> ro...
You don't need to store anything, just check the current logged in user via <code> user_can </code> : <code> global $current_user; get_currentuserinfo(); if ( user_can( $current_user, "role_apple" ) ){ // do something } </code>
Check user's role and store in variable
wordpress
I had this function that counts posts number by type (taken from wordpress codex) <code> function count_user_posts_by_type($userid, $post_type) { global $wpdb; $where = get_posts_by_author_sql($post_type, TRUE, $userid); $count = $wpdb-&gt;get_var( "SELECT COUNT(*) FROM {$wpdb-&gt;posts} $where" ); return apply_filters...
It's not necessary to use <code> $wpdb </code> , a simple <code> get_posts </code> can handle it. Check <code> WP_Query </code> for the full list of parameters. <code> function count_user_posts_by_type( $userid, $post_type ) { $args = array( 'numberposts' =&gt; -1, 'post_type' =&gt; $post_type, 'post_status' =&gt; arra...
Count posts by type including drafts and pending posts
wordpress
I wanna create a simple widget that show an image and text with a link. Something like this: http://jsfiddle.net/aF4UR/ But I want to include this as a widget with fields. For example in the back end: Image: [insert image url here] Image Link [link] Title:[title here] Title link: [insert link here] Text:[text field] An...
The correct question would be "how to create a widget"? No code was initiated. I recommend reading this tutorial: Building Custom Wordpress Widgets Anyway... your widget: <code> class widget_simple extends WP_Widget { // Create Widget function widget_simple() { parent::WP_Widget(false, $name = 'Custom Simple Widget', a...
Create a simple widget
wordpress
I am creating a site which uses normal posts for a blog and the a custom post type for events(generated by the events plugin). I have successfuly used different queries to grab both but I want to combine them into one query. Have tried various things with no luck. Here is query for blog: <code> &lt;?php $mainFeatures =...
I think you are using the wrong <code> post_type </code> for regular posts. <code> $args = array('post_type'=&gt;array('post', TribeEvents::POSTTYPE)); // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); echo '&lt;li&gt;' . get_the_title() . '&...
Combine query_posts() and get_posts() into single query
wordpress
I want to use Myanmar Unicode text on my blog. Unfortunatly, pseudo-Unicode Myanmar fonts are common. So, I am writing a plugin that will suround all Myanmar phrases with HTML span tags, and use css to select the proper font. Everything works fine for content, comments, etc. However, after adding HTML using the the_tit...
Ok, I thought I'd post my final solution up here in case anyone else has the same problem. Basically, I have to add new hooks to my theme files, and then send the modified post title to those hooks. My plugin code now looks like: <code> add_filter( 'the_html_safe_title', 'addThemSpansToPostTitles' ); function addThemSp...
What is the proper filter to add html to a post / page title?
wordpress
I'm using the Custom Comment plugin to add custom fields to my comments. This plugin lets you define more fields for comment to let your visitors include their facebook, twitter and ... in their comments Everything is working as expected. However, the custom fields don't show up when I edit a comment in the admin side....
Inserting a meta box in the Comment edit screen is the same as in the post types screens. But it can only be placed on the wide column, the sidebar seems not to accept other boxes. To capture the data that's being posted, I only found the filter <code> comment_edit_redirect </code> . This has to be adapted to work with...
Show Custom Comment Fields when editing in admin
wordpress
I'm trying to make my widget titles two-colored; the first word white and the second one yellow. I have no idea how I can insert a span before the second word of every widget title so that I can put a color to the span.
<code> add_filter('widget_title', my_title); function my_title($title) { // Cut the title to 2 parts $title_parts = explode(' ', $title, 2); // Throw first word inside a span $title = '&lt;span class="my_class"&gt;'.$title_parts[0].'&lt;/span&gt;'; // Add the remaining words if any if(isset($title_parts[1])) $title .= ...
Insert a span inside widget title to give a different color to the second word
wordpress
I am using WP Supersized and Easy Fancybox Wordpress plugins. Everything is works fine till the point I am not clicking the link to open a fancybox. Image is opening perfectly just having some issues with the position. Its shifting towards the left on opening up. Here is the link to my demo page where I am using fancyb...
I spotted out the answer for this. Here is the culprit the culprit: the jquery.animate-enhanced.js file that had been added since version 3.1.2 is creating the issue. Comment out this line : <code> wp_register_script('jquery_animate_enhanced', content_url().'/plugins/wp-supersized/js/jquery.animate-enhanced.min.js',arr...
WP Supersized & Easy Fancybox Conflict
wordpress
Is there any way to list the child categories only? I just want to filter the Parent Categories
The following code is to display the subcategory instead of parent . I am not sure this is the one as you are trying too. <code> &lt;ul&gt; &lt;?php $catsy = get_the_category(); $myCat = $catsy-&gt;cat_ID; wp_list_categories('orderby=id&amp;child_of='.$myCat); ?&gt; &lt;/ul&gt; </code>
How to list only child categories?
wordpress
I have the following script and enque function, and the site properly renders it in the html head, however when I click the link to the css and javascript files the i get a url not found, however the url is correct. I changed the permissions to 777 for all the folders so I am not sure why it cant see it. You can view t...
You have called your theme <code> mrskitson.caVersion#3 </code> . Do you know what a hash symbol ( <code> # </code> ) does in a URL? So, browsers are trying to load the script here: <code> http://update.mrskitson.ca/wp-content/themes/mrskitson.caVersion </code> And then jump down to an element with ID matching everythi...
All of my Scripts and Enques are getting file not found
wordpress
I'm running into a problem with my plugin which is essentially an admin page that includes simple_html_dom parser to edit some information scraped from some websites. Let's assume I want to parse this page: stackexchange-url ("stackexchange-url And store all question Titles as $item[0] and question's URLs as $item[1]. ...
Maybe I'm missing something, but in your first <code> print_r($articles) </code> , the global variable <code> $articles </code> is in the scope of the <code> getArticles() </code> function, so we're all good there. But, in your second <code> print_r($articles) </code> , which is happening after the closing brace of the...
Creating plugin using simple_html_dom parser?
wordpress
I am attempting to change the name format that Wordpress uses to rename uploaded files. For example, when I upload an image with filename "cat-picture.jpg" Wordpress will create scaled versions and rename the filename to variations of "cat-picture-{WIDTHxHEIGHT}.jpg". Is there a way I am able to move this width &amp; h...
I've managed to do it with the filter <code> image_make_intermediate_size </code> . Probably all the <code> path/filename.extension </code> dismembering and remaking could be optimized or made in a single stroke fashion, but alas, I'll let that to the reader: <code> // The filter runs when resizing an image to make a t...
Rename image uploads with width in filename
wordpress
I have a page template that I want to be able to show in two different modes: a regular mode and a bare-bones mode, where there is no header, footer, sidebar, etc. My hope is that I can get this done using a parent-child url, like so: Normal view: http://sample.com/mypage/ Barebones view: http://sample.com/mypage/clean...
stackexchange-url ("Add an endpoint to your post permalink"), name it <code> clean </code> . In your callback for <code> template_redirect </code> use a special <code> header.php </code> or none at all. Do not forget to call <code> exit; </code> ; otherwise WordPress will load the default template files later.
How to show one page with two different templates
wordpress
I have very few knowledge on oo php and databases, and I am simply trying to insert data in my wp_pagesvisites table but I am having some trouble with this error message. This is my script: <code> $wpdb-&gt;insert( 'wp_pagesvisites', array( 'Adresse_IP' =&gt; $ip, 'Post_ID' =&gt; $id, 'Timestamp' =&gt; $time ) ); </cod...
<code> $wpdb </code> is a global variable. You have to take it into your function’s scope first … <code> global $wpdb; $wpdb-&gt;insert(); </code> … or access it per <code> $GLOBALS </code> … <code> $GLOBALS['wpdb']-&gt;insert(); </code> And I would use always lowercase keys; this is just a useful convention.
$wpdb error (Call to a member function insert() on a non-object)
wordpress
On WordPress Codex there are this CSS styles listed, its a quite big list of styles but it seems they are doubled unnecessary. It says: Each Theme should have these or similar styles in its style.css file to be able to display images and captions properly. The exact HTML elements and class and ID values will depend on ...
The most definitive and up to date answer about best practice can come probably only from the wordpress.org theme review team, and right now they are different from the codex. just quoting it here, but I'm sure it might change with time Themes are required to support the following WordPress-defined CSS classes, or simi...
Are the wordpress Core css styles really all nessasary?
wordpress
I am building a movie database site and I am wondering in a problem and asking how should I solve this problem. I have several custom post types <code> movie </code> , <code> actor </code> , <code> person </code> and others. I want to integrate award feature for movies and actors. So I'll be able to assign awards to a ...
Have a <code> nomination </code> post type. So your awards post type doesn't represent an award, it represents the 'nomination' of an award, a record that it was won or lost by someone/something. You then define the attributes such as the year, the type of award, its classification etc using taxonomy terms. To assign i...
Taxonomy/Custom post type structure suggestion on a movie site
wordpress
I know it is easily possible to add a post-type count for a custom post type to the right now dashboard widget. However I wonder if it is also possible to remove stuff from this widget. E.g. I don't have normal posts on my current wordpress site and I don't need the count to say 0 posts and 0 categories and 0 tags all ...
There is no filter in PHP, so we have to use JavaScript: <code> add_action( 'admin_footer-index.php', 'wpse_82132_hide_rows' ); function wpse_82132_hide_rows() { $rows = array ( # 'posts', # 'pages', 'cats', // meoww! 'tags', # 'comments', # 'b_approved', # 'b-waiting', # 'b-spam', ); $find = '.' . join( ',.', $rows );...
remove post and categories/tags count from right now dashboard widget
wordpress
Just trying to get a scope of work estimation for a project I need done. My wordpress theme has a custom menu that works best with featured image thumbnails that are 50x50 pixels in size. If the user builds their site after installing my theme, its no problem, since I'm ensuring that all uploads create a 50x50 thumbnai...
There are lots of plugins that do this one way or another including: http://wordpress.org/extend/plugins/regenerate-thumbnails/ http://wordpress.org/extend/plugins/dynamic-image-resizer/ I wouldn't recommend reinventing the wheel. If you're particularly worried about it, you might looking into TGM Plugin Activation to ...
Can this be done? Create 50x50 thumbnails of all existing featured images?
wordpress
Supposing I have an existing table(already created in dB) that handles user-registration (a plugin) and insert data using the $wpdB-> insert like this: <code> $success = $wpdb-&gt;insert( $wpdb-&gt;mytable, array( 'first_name' =&gt; $first_name, 'last_name' =&gt; $last_name, 'email' =&gt; $email, 'activation_key' =&gt;...
No, the column must exist before you insert data into it. Otherwise the query will fail. You should edit your table creation SQL query to accommodate the new column. Then, run it through <code> dbDelta() </code> again. <code> dbDelta() </code> will compare your query and the table structure and only create the missing ...
How to insert data to a database table when the field is not yet created?
wordpress
it feel like this should be easy. I want to add the post tags inside the body of some posts. I was thinking that creating a shortcode may be the answer. I came across these 2 pieces of code: To display the tags... <code> &lt;p&gt;&lt;?php the_tags(); ?&gt;&lt;/p&gt; </code> To create a shortcode... <code> function show...
Just add <code> the_tags() </code> to the shortcode: <code> function wpse_82190_tags(){ return the_tags(); } add_shortcode('tags', 'wpse_82190_tags'); </code>
Include tags in the body of a post
wordpress
I have run my theme through WordPress theme checker to see if it can be submitted to WordPress.org. I encountered this error: REQUIRED: Could not find wp_link_pages. See: wp_link_pages But this is not true. I am using a custom function <code> wp_my_own_link_pages() </code> which is a replacement for <code> wp_link_page...
First, this question should be asked on the Theme Reviewers mail-list, not at WPSE. If you want official answers, you should use the official communication channels. But to answer your question in brief: Themes that implement core features/functionality are required to support the core implementation of those features/...
REQUIRED: Could not find wp_link_pages. See: wp_link_pages by Theme Checker
wordpress
I am new to WordPress and I would appreciate some cool advice here. I have changed the <code> header.php </code> file in the Editor to include an image. I wonder if it is possible to automatically display one of 9 possible images depending on the date (ie. rotate them)
The following code will cycle between the 9 pics. 1st day of the year = pic0, 2nd = pic1...359th = pic9, 360th = pic0, etc. <code> &lt;?php $pic_array = array( 'pic0', 'pic1', 'pic2', 'pic3', 'pic4', 'pic5', 'pic6', 'pic7', 'pic8', ); $d = (int) date('z') % 9; $todays_pic = $pic_array[$d]; echo $todays_pic; </code> Hop...
Rotate images in header based on date
wordpress
I'm calling my comments the ol' fashion way: <code> &lt;?php wp_list_comments('avatar_size=60'); ?&gt; </code> I would like to be able to position the 'Reply" link where I choose. Right now, it defaults to the bottom of the comment. Sure, I can move it via CSS - but what if I want to place it after the dater or usernam...
Use a stackexchange-url ("custom callback") to render the comment content. Inside of the callback function call <code> comment_reply_link() </code> wherever you need it: <code> comment_reply_link( array_merge( $args, array ( 'add_below' =&gt; 'comment-body', 'depth' =&gt; $reply_depth, // + 1 to offer always a reply li...
Repositioning 'Reply' Link in Comments
wordpress
I want to build an alert for users who visit my WordPress blog. Is there a conditional function like <code> is_home() </code> to detect if someone visits the blog the first time ? I want to send the alert to every new user no matter on which site he entered.
No, there's nothing in the core like that. You can set a cookie and do it simply enough (warning: untested code follows). <code> &lt;?php function is_first_time() { if (isset($_COOKIE['_wp_first_time']) || is_user_logged_in()) { return false; } $domain = COOKIE_DOMAIN ? COOKIE_DOMAIN : $_SERVER['HTTP_HOST']; // expires...
How to detect first visit of a user?
wordpress
The actual post type support categories and I want to add also support for tags. I have this code: <code> register_taxonomy( 'category_' . $slug, array( $slug ), array( 'hierarchical' =&gt; true, 'label' =&gt; "$slug Categories", 'singular_label' =&gt; "$slug Category", 'rewrite' =&gt; true ) ); </code> So, I was tryin...
The categories your code creates is a custom taxonomy, not the default post <code> category </code> taxonomy. Anyway, if you want to add support for the default post tags taxonomy, the name is <code> post_tag </code> and can be added via the <code> taxonomies </code> argument in your <code> $portfolio_args </code> : <c...
Registering tags taxonomy for a custom post type
wordpress
WordPress Version: 3.3.2 Assumption, My post in category 7 have 9 posts during October 2012. by accessing www.example.com/2012/10/?cat=7 I am able to view all in one page. No issue, however, I create custom page <code> category-7.php </code> in theme folder. <code> //listed category per page = 6 $query = 'posts_per_pag...
The problem is that you're stomping the main query by using <code> query_posts() </code> . Don't do that. Instead, filter the main query via <code> pre_get_posts </code> : <code> function wpse82113_filter_pre_get_posts( $query ) { if ( is_category( 7 ) &amp;&amp; $query-&gt;is_main_query() ) { $query-&gt;set( 'posts_pe...
View Achive with Category Filter, but Page per post not working
wordpress
I want to be able to render post in two different styles (2 templates). For example, let's say I have the post ID 133, I would like two URLS to access it and so it renders where different template would apply. lorem.com/render1/133 lorem.com/render2/1333 for example... or it could be something like: lorem.com/post/133 ...
Your best bet would probably be the Rewrite Endpoints API . The API allows you to create post URLs with endpoints like <code> lorem.com/post/133/json/ </code> or <code> lorem.com/post/133/print/ </code> . You'll find useful code examples in the link provided.
1 post, 2 templates
wordpress
This is the code to display popular post on front end, however the problem is the data is not saving from the back end. Like i want to show only 3 popular posts on front-end so i select the option 3 but its not saving. However when i pass the static value for <code> $popularpostcount </code> then this code works <code>...
Replace this line in form function: <code> echo "&lt;select name='popularpostcount' id='popularpostcount'&gt;"; </code> with: <code> echo "&lt;select name='".$this-&gt;get_field_name('popularpostcount')."' id='".$this-&gt;get_field_name('popularpostcount')."'&gt;"; </code>
Sidebar widget to show popular post not working?
wordpress
The login form on the page wp-login.php has a link at the bottom that says "Back to website-name " This link always redirects to the home page I would like it to redirect to the page the user has come from. I imagine this requires a hook added to functions.php but I'm not sure how and could not find anything while sear...
You can achieve that using Javascript and <code> login_footer </code> action hook to change the <code> href </code> attribute of the <code> Back to </code> link: <code> &lt;?php add_action('login_footer', 'ad_login_footer'); function ad_login_footer() { $ref = wp_get_referer(); if ($ref) : ?&gt; &lt;script type="text/j...
Change 'Back To Website' link in wp-login.php
wordpress
I have a pretty simple question. I want to make a static about page for my wordpress site. I don't like the format of the wordpress static pages that are managed through the control panel so I thought I would make my one custom page where I would have full control of the layout, formatting &amp; content. I have experie...
I want to make a static about page for my wordpress site. I don't like the format of the wordpress static pages that are managed through the control panel... But that's how the WordPress CMS is designed to be used. For static pages, create static pages . so I thought I would make my one custom page where I would have f...
Custom static page get_header error
wordpress
How do I get a post's ID? I know I can use the_ID(), but I have to use it in The Loop. How can I get the post's ID without the loop? Because I think using the loop just to find the post's ID will slow down my script. Maybe i'm wrong. Please help me :) Thank you!
If you're on a singular page, sometime after <code> init </code> and all the query variables have all ben set up you can use <code> get_queried_object_id </code> or <code> get_queried_object </code> . <code> &lt;?php if (is_singular()) { $post_id = get_queried_object_id(); // or get the whole object $post = get_queried...
Get a post's ID
wordpress
Is there a fast way to retrieve a specific post by a unique meta value? I could run a meta_query and then loop through the first value to get the post's ID, but I am wondering if there is any other that I am overlooking. Is it possible to add a column to the wp_posts table? Or is there some other way to add a second un...
I am just incredible stupid here as this can be easily done by a simple WP_Query: <code> new WP_Query( array( 'post_type' => 'shop_order', 'meta_key' => $meta_key, 'meta_value' => $meta_value ) ) </code> However, I decided to compare the actual generated SQL of the get_posts() with a 'post_where' filter solution which ...
Get a single post by a unique meta value
wordpress
I have <code> custom meta field </code> that I use for the post <code> rating </code> . So I want to display posts by the <code> date </code> and the <code> rating </code> , but only for the posts that have specific rating. For example, I want to display posts with rating above 3, and in this order: by the rating (high...
Basically, I am reading right out of the Codex page for <code> WP_Query </code> . You want a <code> meta_query </code> similar to this with an <code> orderby </code> parameter with the two values you want to order by . The first is dominant. <code> $args = array( 'post_type' =&gt; 'post', 'meta_query' =&gt; array( arra...
How can I sort posts by the date and a custom meta field?
wordpress
I created a portfolio page to show my works for my theme Everything is ok on my portfolio page, but when I click on an link to go to the portfolio object page, it uses the template's single.php page. I would like it to use the template page I created "single-portfolio.php". How do I do this?
You have to use the Slug of your Custom Post Type "portfolio" for the filename, as you pointed out, <code> single-portfolio.php </code> is correct if your slug is "portfolio". You just have to take one more step, create the file in the Theme directory (the same folder where your <code> single.php </code> is located). W...
How to create an Single-Portfolio page?
wordpress
I update user info using <code> wp_update_user </code> function. I also need to update the table <code> wp_bp_xprofile_data </code> . Is there any function, where I can update data on <code> wp_bp_xprofile_data </code> table?
This is how I would update a field named 'Address': <code> function updateAddress() { global $current_user; get_currentuserinfo(); $newAddress = '123 New Street'; xprofile_set_field_data('Address', $current_user-&gt;id, $newAddress); } </code>
How to update BuddyPress xprofile fields programmatically?
wordpress
I guess that this should be an easy one but I haven't yet find the proper solution. I want to limit the depth of wp_list_pages so as not to display the pages of the last level. So supposing that parent page A has 3 levels of pages I only want to list first 2 levels. I was looking for a function to count the maximum dep...
This is a little tricky, and my solution may not be the best for the performance. You may add this Value as a Custom Field to the Page, so you do not have to query it everytime. <code> // get the ancestors of the page, and check if the page is toplevel $parent = array_reverse( get_post_ancestors( $post-&gt;ID ) ); if (...
dynamically limit depth of wp_list_pages
wordpress
I am currently using a plugin called Sidebar Login which allows users to bypass the dashboard and go directly to the site. However, when users login via <code> /wp-login.php </code> (e.g. when they click on their verification links in their emails), they are once again sent to the dashboard. I would like for users to b...
You can achieve this by using the Plugin Peter's Login Redirect . It allows you to send users to a specific page after login, based on the user capabilities. So you can allow administrators to go to the admin section, while members are redirected to the front page. If you want to prevent users from ever seeing the admi...
send users logging in from wp-login.php directly to home page of site, rather than dashboard
wordpress
I am using Event Manager plugin. I want to use many of the shortcodes via php code. e.g [events_calendar]
In general, you can do any shortcode with <code> do_shortcode() </code> (see codex ). But if they have a template function available, its probably best to use that. <code> echo do_shortcode('[events_calendar]'); </code>
How to use 'Event Manager Shortcodes' plugin via the php code?
wordpress
My blog have many author. I can list all author. All Author list: <code> &lt;ul&gt; &lt;?php wp_list_authors('exclude_admin=0&amp;optioncount=1&amp;show_fullname=1&amp;hide_empty=1'); ?&gt; &lt;/ul&gt; </code> But I want to sort in a special way. For Example im currently viewing Tech category page, I want a list of aut...
I assume that you would be providing the author IDs in the widget options. And that the authors would be displayed in the order they were listed. Assuming the input would be -> 3,10,12 You can have the following code to display the authors with that user ID in that order: <code> $user_ids = "3,10,12"; //this is assumin...
How can i do custom author list?
wordpress
I was wondering which one I should use. Maybe one use widgets and the other one doesn't?
Please refer to the <code> get_sidebar() </code> and <code> dynamic_sidebar() </code> Codex entries. The <code> get_sidebar( $slug ) </code> template tag includes the <code> sidebar-$slug.php </code> template-part file. The <code> dynamic_sidebar( $slug ) </code> template tag outputs the <code> $slug </code> dynamic si...
What is the difference with get_sidebar and dynamic_sidebar?
wordpress
I wish to remove the image classes generated by default in the output whenever post_thumbnail() is called - <code> &lt;img width="1024" height="768" src="http://example.com/wp-content/uploads/2013/01/example-1024x768.jpg" class="attachment-large wp-post-image" alt="Yet another example"&gt; </code> I've read a bit about...
You might try something like this in your <code> functions.php </code> : <code> //remove class from the_post_thumbnail function the_post_thumbnail_remove_class($output) { $output = preg_replace('/class=".*?"/', '', $output); return $output; } add_filter('post_thumbnail_html', 'the_post_thumbnail_remove_class'); </code>
Remove image classes from post thumbnail output
wordpress
I am looking to develop a shortcode that all wordpress.com users can use. Should I proceed with developing a plugin? I know users on wordpress.org can use the plugin but I am confused on how to make wordpress.com users use the shortcode as wordpress.com does not let the users to install a plugin. Is it done in the back...
For anything related to adding code to wordpress.com you should contact automatic .
Developing a wordpress.com shortcode
wordpress
I'm developing a plugin that uses custom capabilities. Some of those capabilities need to be added to all users who are super admins. Currently, I'm using this code: <code> $supers = get_super_admins(); foreach ( $supers as $admin ) { $user = new WP_User( 0, $admin ); $user-&gt;add_cap( 'my_cap' ); $user-&gt;add_cap( '...
Although this isn't well documented, "Super Admin" is not a role (in that it is not an actual role object). It's more like a special "status". A list of users who are Super Admins (also called "network admins" or "site admins") are stored in a database site-option record called 'site_admins'. Generally, adding a capabi...
Adding capabilities to super admins
wordpress
I'm trying to show all posts posted under the month, so 2012 December post 1 post 2 November post 1 post 2 The posts are to appear under my custom taxonomy template, so taxonomy-pubyear.php and I'm able to retrive all the posts for that term using the basic loop. If I add get_the_year('F') in the loop then the same mon...
Save the current month in a variable and check it for each post, only output it when it changes: <code> $current_month = ''; while( have_posts() ): the_post(); $this_month = get_the_time( 'F' ); if( $this_month != $current_month ){ $current_month = $this_month; echo $current_month; } the_title(); endwhile; </code>
Order posts by month - in custom taxonomy template
wordpress
My theme does not seem to be showing me the comments section, this is the PHP code I have in my <code> index.php </code> file inside the template folder <code> &lt;!-- Start the Loop. --&gt; &lt;?php get_header(); ?&gt; &lt;?php get_footer(); ?&gt; &lt;?php get_sidebar(); ?&gt; &lt;?php if ( have_posts() ) : while ( ha...
if you look in the twentyTwelve theme. you can see how they get the comments. Look in the full-width.php file and you can see this code <code> &lt;?php comments_template( '', true ); ?&gt; </code> this will call the code to get your comments section. Now you must make sure that your theme has the comments.php. You can ...
How do I get the comments section to show up?
wordpress
I have a custom meta box created using Rilwis meta box script(http://www.deluxeblogtips.com/meta-box/) inside my theme functions.php. It has 2 text fields, one field is required to fetch results from api, so, it needs to be visible on the custom meta box. But, the other field stores a serialized array which is the resp...
Using a leading underscore will hide the field's value from the default WordPress Custom Fields section, not the meta box you create via the plugin. If you don't want the field visible in your custom meta box, don't add the field to the meta box at all, it really serves no purpose there anyway. You can manage the field...
How can I hide custom field from users used for caching response from external api?
wordpress
I wanna pull the data from this area "see the red area on the image below" Out to a specific template I have a page template named page.php <code> &lt;div class="contentholder"&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php get_template_part( 'content', 'page' ); ?&gt; &lt;?php comments_template( '', ...
While inside a query loop, this function will output the current posts title: <code> the_title(); </code> This function will output the content: <code> the_content(); </code> What I suspect has happened however is that you are instead calling <code> get_template_part( 'content', 'page' ); </code> and expecting it to ou...
Pull the content out of a page
wordpress
My page in question is here. I have tried to add a <code> comments.php </code> to my custom theme so I can remove the website field and so I could edit the default values of the fields and remove the labels. When I add a <code> comments.php </code> all of my comments disappear and the comments are no longer functional....
A little late, but you could also add the following to your theme's functions.php file: <code> /** Comment Form Function Defaults */ add_filter('comment_form_defaults','my_comment_defaults'); function my_comment_defaults($defaults) { global $user_identity, $id; if ( isset($post_id) ) $id = $post_id; else $post_id = $id...
I don't have comments.php... how do I customize my comment fields
wordpress
i am writing a plugin that injects unescaped content (including javascript) into a post. i'm storing this content as a custom field, and am wondering if there are any built in ways to prevent users from editing specific custom fields.
Simply use a Custom Field with its name starting with an underscore , so it won't show up in the CF meta box, eg, <code> _field_name </code> instead of <code> field_name </code> . It will be hidden for all roles, but if you are manipulating its value only through code, then no problem. If you need to manipulate the val...
can i limit editing specific custom fields to certain roles?
wordpress
I usually have a gallery in posts. I want to display random image and its post-title from a random published post which can lead to permalink like related posts below a post. I used this code: <code> &lt;?php $args = array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; 3, 'post_status' =&gt; null, 'post_parent' =...
The solution to this is that you have to search for posts first, and afterwards to images to the post. In my code I included a parameter <code> exclude </code> to ensure the current post is not delivered again. Please keep in mind that if a post has no Image, none will be shown. Also, I did not include stylings or fall...
Display random gallery images and its parent post title leading to parent post permalink
wordpress
What i was doing previously, are as follows - I copy the wordpress base theme (like twentytwelve in wordpress 3.5) Rename the folder and converted index.html of my HTML to index.php for wordpress theme. Replace style.css with my current style.css. Is it the right way of theme development or some else better technique c...
I like to do this as follows: Go to underscores.me, fill out the theme name, and download the theme. Strip out the parts of this (somewhat clean) template that don't want to use. Start building your own template with the functionality that you wrote. This way you will have a clean template to start with, and no core th...
Optimal solution to develop a wordpress theme?
wordpress
I created a new post type named "Video". When I create post for the post type, posts is ordered by <code> title ASC </code> . Is it possible to order posts by date DESC please ? <code> register_post_type('Videos', array( 'labels' =&gt; array( 'name' =&gt; _x('Videos', 'post type general name'), 'singular_name' =&gt; _x...
Alright, You can just hook into the filter pre_get_posts and check is_admin . Put this in your theme or plugin: <code> function wpse_81939_post_types_admin_order( $wp_query ) { if (is_admin()) { // Get the post type from the query $post_type = $wp_query-&gt;query['post_type']; if ( $post_type == 'Videos') { $wp_query-&...
How to order posts of a custom post type by date DESC in dashboard Admin?
wordpress
Hi I'm using the code below to show different header images in my custom template archives. Only problem is that it is also showing the headers in the category templates. go to http://tv-cafe.com/category/video that image at the top isn't suppose to be there, how do i get that to not show. <code> &lt;?php if ( ! is_hom...
You can achieve that by changing the conditional to <code> if ( !is_home() &amp;&amp; !is_archive() ) </code> Also consider using <code> if </code> and <code> else if </code> . So your optimized code would be: <code> &lt;?php if ( !is_home() &amp;&amp; !is_archive() ) { if ( get_post_type() == 'pretty-little-liars' ) {...
Stop header code from showing in category page?
wordpress
I have created a download link for my plugin using add_submenu_page. When the link is clicked it gathers some files into a zip, then outputs the contents to the browser like so: <code> header('Content-Type: application/zip'); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filenam...
I think you'll have to hook an earlier action and check if your subpage is being loaded, when the function to render the subpage happens it's too late to send headers. Your subpage's rendering function could just be blank because the earlier action would override it. I tried this with a subpage of <code> themes.php </c...
Prevent Admin gui output from page added using add_submenu_page
wordpress
i'm trying to put a search page on my site. I thought it would be simple, but I am having no success. I have put a form in my header.php (which I call in my search.php page (include "header.php")) that looks like that: <code> &lt;form action="&lt;?php bloginfo("template_directory") ?&gt;/search.php" method="get"&gt; &l...
You <code> form </code> action value is wrong. It should be <code> home_url() </code> . WordPress will pick the search template automatically then. The search field has to use the name <code> s </code> : <code> &lt;input type=search name=s&gt; </code> Otherwise WordPress will not recognize the request as a search reque...
Trying to put a search page on site
wordpress
I have the following function in my functions.php. I am trying to disable the admin from receiving emails every time a new user joins the site. However, the admin is still receiving emails. Is there something wrong with the function? And is this part of the WP options by any chance? I couldn't find the option anywhere....
You need to implement your function earlier than you are. It seems that the "real" wp_new_user_notification() (from wp-includes/pluggable.php) is getting created before yours is. To test, remove the <code> if ( ! function_exists( 'wp_new_user_notification' ) ) : </code> from your code. You should be getting an error. Y...
disabling emails received by admins every time a new user signs up (function not working)
wordpress
I have a questions related to BuddyPress: What's the use of <code> wp_bp_xprofile_data </code> table? How does the data in the table get updated? And when any user updates his information - does the data in this table get updated?
The <code> wp_bp_xprofile_data </code> table holds all of the custom fields used on the front-end by BuddyPress. It is independent of the WordPress user meta. All of the functions that interact with this table can be found in <code> bp-xprofile/bp-xprofile-functions.php </code> .
BuddyPress: What's the use of wp_bp_xprofile_data table and how does it get updated?
wordpress
What I'd like to do is if the NextGEN gallery has more than one page (pagination) execute some code...I got close: <code> &lt;?php $nggpage = get_query_var('nggpage'); if ($nggpage &gt; 1) { echo "duck"; } ?&gt; </code> This code appears on all pages but the first page, how do I make it work on the first page? Because ...
I figured it out!! My final code looks like: <code> &lt;?php $images = intval($wpdb-&gt;get_var("SELECT COUNT(*) FROM $wpdb-&gt;nggpictures")); $ngg_options = nggGallery::get_option("ngg_options"); $maxElement = $ngg_options["galImages"]; if ($images &gt; $maxElement) { echo "duck"; } ?&gt; </code> Basically the code c...
NextGEN Conditional Statement
wordpress
I just did a normal form that redirects the results from index.php to search.php, where I pasted the normal loop code of my index.php that displays the latest posts, and I noticed only the posts from my search query appears. I did not put any filters with $_GET in the loop, is it possible search.php automaticly filters...
The loop doesn not display the latest posts, it just shows the posts the main query has found. On your search page the main query returns search results, and you can change its order (we have plenty of examples for that on our site). WordPress looks for the parameter <code> s </code> or <code> /search/ </code> in the r...
Does search.php autofilter The Loop?
wordpress
I am looking to echo the post title at the beginning of each post. I've tried adding the following to <code> functions.php </code> with no luck: <code> function add_post_content( $content ) { if ( ! is_feed() &amp;&amp; ! is_home() ) { $content .= '&lt;p&gt;.get_post('post_title').&lt;/p&gt;'; } return $content; } add_...
Use <code> the_title() </code> : <code> function add_post_content($content) { if(!is_feed() &amp;&amp; !is_home()) { $content = the_title( '&lt;p&gt;', '&lt;/p&gt;', FALSE ) . $content; } return $content; } add_filter('the_content', 'add_post_content'); </code> The first two arguments are for <code> $vefore </code> and...
Echo post title in post
wordpress
What's the relationship between performance and database size in WordPress? Does a bigger DB mean that my site will be slower? My DB size is currently 360mb. I also noticed that I have some tables left over from old plugins I have now deleted, do those empty or semi-empty tables influence performance?
A bigger database isn't per definition slower, and a smaller database isn't per definition faster. When a table contains a large amount of information, it could take longer for queries to get their results, depending on the type of query, the amount of data you want to return, the table structure attributes, types and ...
Relationship between performance and database size
wordpress
I am doing some optimisation on my site and would like to take some readings on page load speed in order to determine what works and what not. Since my internet connection is unreliable I cannot just test on how long it takes to download the page to my laptop, but I need an external reliable source to test. Any good to...
Try either of these for your site, either one will guide you to better page load performance. http://webpagetest.org http://gtmetrix.com
What's a good tool for speed benchmarking?
wordpress
I am trying to build my first plugin but am receiving the following error: Warning: Cannot modify header information - headers already sent by (output started at <code> /wp-admin/includes/template.php:1642 </code> ) in <code> /wp-includes/pluggable.php </code> on line 876 But here's the thing: template.php isn't 1600 l...
I'll guess your include is failing. If it's in the same directory as your main plugin file, try: <code> include( plugin_dir_path(__FILE__) . '/admin.php' ); </code>
Plugin getting Cannot modify header information errors
wordpress
I'm using Wordpress Form Manager Plugin to design a table to display race winners for an athletic event. <code> &lt;table class="fm-data"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td class="fm-item-cell-lane"&gt;7&lt;/td&gt; &lt;td class="fm-item-cell-bib"&gt;124&lt;/td&gt; &lt;td class="fm-item-cell-fullname"&gt;Person Two&lt;...
many ways to do it, not best but easiest is problably javascript: <code> &lt;script type="text/javascript"&gt; jQuery('.fm-item-cell-country:contains("USA")').addClass('americanflag'); &lt;/script&gt; </code> from that you edit your css (which I guess you're more comfortable with), setting property for each class (.ame...
How do I use CSS or PHP to customize Wordpress Form Manager Plugin Table?
wordpress
I have a plugin that is conflicting with some default wordpress functions. In the post and page creating/edit areas. I only need my functions on my settings pages. I have the js file loading in admin, no problem. Can I tell the script not to load unless I'm viewing the settings pages for my plug?
You need to use a plugin page-specific script enqueue hook. Edit Best-practice method is to use <code> admin_enqueue_scripts-{hook} </code> , rather than <code> admin_print_scirpts-{hook} </code> . But, because you're targeting your own Plugin's admin page specifically, either one is perfectly fine. The hook to avoid i...
How do I only load a plugin js on it's settings pages?
wordpress
I'm building a way to upload multiple files for an announcement custom post type on the front end. My function here uploads any number of files succesfully so I can see them under "Media" in WordPress... attached to the post. I need to be able to store the url of the file in a custom field. When I use <code> update_pos...
<code> update_post_meta() </code> will update the value for the provided key if the key already exists in the database and then returns true, which is what you're seeing for subsequent calls. It only returns the ID of the post meta if the key didn't exist previously. If you want to store multiple values (rows) with the...
update_post_meta only updating on last loop of foreach
wordpress
I am somewhat of a Wordpress beginner so please excuse any ignorance. I have installed the plugin The Events Calendar (http://tri.be/wordpress-events-calendar/) and it works pretty much perfectly. One issue I have is the URL format for an event, which based on the URL slug is <code> /upcoming-event/[event title]/ </cod...
You could just try to change the slug to the value you need for each event. The problem arises if you have the same event twice (or more) in the same month though. You will need to create a new title for the event. you can try this plug-in: http://wordpress.org/extend/plugins/custom-post-type-permalinks It might help y...
Date in the URL with The Events Calendar
wordpress
I am working on an advanced search on wordpress based on custom taxonomies. I've been stuck for 72h so I was hoping to have some help or thought... Step 1 --- in the js file the query strings are created like that: <code> if (jQuery('#s').val() == ''){ URL = "/?genre=" + genre + '...other Stuff' #content'; }else{ URL =...
It sounds like you're looking for <code> wp_localize_script() </code> which lets you pass data to a script that is already enqueued. It works roughly like this: <code> &lt;?php // assuming your script is already registered wp_enqueue_script( 'wpse_81817' ); // Do the array building of terms you plan on doing $wpse_8181...
get data from wp-query, outside the loop & without url change
wordpress
Normally in a plugin I would add styles using wp_enqueue_style. However, I am currently creating a plugin that only needs a few lines of CSS and I am wondering if it might be better to serve the styles inline to save a request. Obviously there are many advantages to using wp_enqueue_style, but are they worth the extra ...
TL;DR; <code> Enqueue </code> Using external stylesheet PRO: All your styles are in one spot. PRO: Reduces web page coding. PRO: Easier to maintain the plugin. PRO: Can use hooks to alter location of the file. PRO: Can use hooks to unqueue the file. PRO: Can use minify styles automatically. CON: Might add extra HTTP re...
Is it ever okay to include inline CSS in plugins?
wordpress
I'd like to create a Q&amp;A-type forum for my wordpress site, where anyone can submit a question, and then the forum admin would answer the question and then post the question/answer combination. How I'm thinking this works would be along the lines of the question object being a Post, and then the answer being a reply...
This creates a custom meta box and the contents of the textarea field it contains are being saved as a comment to the post. Please note: Built with code sample adapted from the Codex. Relevant functions: <code> add_meta_box </code> and <code> wp_insert_comment </code> . I removed <code> comment_author_IP </code> and <c...
Commenting on a post from the admin panel?
wordpress
How can I query all the posts from either the custom post type ('videos') or with a post category ('video') in a loop? I've managed to create a query that combines the posts from a custom post type and the normal posts using the code below, but am struggling with achieving the same with a custom post type and a post ca...
Must have both The following arguments array searches for the post-type-slug <code> videos </code> and category-slug <code> video </code> . It doesn't use pagination by setting <code> posts_per_page </code> to -1 and only returns published posts. <code> $args = array( 'post_type' =&gt; 'videos', 'category_name' =&gt; '...
Combining custom post type and post category
wordpress
I have a custom post type called newsletter. Once the newsletter is created I want to create a link to download the newsletter from the admin section (the newsletter post type is not accessible from the front end of the wordpress site). When the download link is clicked it will run a function in my plugin. The question...
You want (probably) <code> add_submenu_page </code> . The first parameter-- the one listed as <code> $parent_slug </code> in the Codex is going to be <code> edit.php?post_type=your-post-type-name </code> , like this (mostly cribbed from the Codex page): <code> function add_submenu_wpse_81844() { add_submenu_page( 'edit...
Creat new admin url for custom post type
wordpress
my single posts is getting 31 query from mysql. I checked all queries. I saw this query. I am using last posts and categories widget. I think there query is unnecessary.How to remove theme Query: SELECT option_value FROM xy_options WHERE option_name = 'widget_pages' LIMIT 1 Query: SELECT option_value FROM xy_options WH...
Best I can tell is that those default widgets get options from the database as their classes are constructed, so there's no way to prevent the DB queries without disabling those widgets entirely. Depending on your needs, you may want that slight performance bump and do not need the widgets, in which case you can use th...
Remove Unnecessary Mysql Query
wordpress
<code> // Post views function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } function setPostViews($postID) { $count_ke...
<code> // Post views function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } if ($count == '1') { return $count.' View'; } else { $count = number...
Post Views Code Hacks
wordpress
I tried all solutions of the topics here but I haven't been able to find a solution. I made a Plugin for a Shortcode. My problem is that the plugin code get always loaded above the content. I already found out that it comes from the use of <code> echo </code> . Instead I should use <code> return </code> . But as soon I...
First, declare your variable: <code> $return = ''; </code> Then, throughout the code, concatenate items: <code> $return .= '&lt;div class="sp shadow"&gt;&lt;img src="..."&gt;&lt;/div&gt;'; $return .= '&lt;h3&gt;Videos&lt;/h3&gt;'; </code> And finally, return the result: <code> return $return; </code>
Wordpress Shortcode loads at the top
wordpress
I'm relatively new to Wordpress and I received a site theme that was developed by outsourced developers. Due to the inevitable scope creep, i've had to modify pages to work with the new scope. http://dsi.sva.edu/news-and-events/ This page is populated by custom fields. Since it's a news page, we want the newest article...
WP_Query is your friend. Combined with featured images, you should be able to do this as a page template with a WP_Query call and loop. This is the html for the top post at the moment: <code> &lt;li class=""&gt; &lt;a href="http://dsi.sva.edu/cheryl-heller-named-in-top-100/"&gt; &lt;img src="http://dsi.sva.edu/wp-conte...
Rewriting a page driven by custom fields to populate a page dynamically, like posts
wordpress
How can I disallow contributors on my site from seeing what other posts are published on the site, and only see their own?
I hope you are talking about wp-admin section. If yes just place this code in your <code> functions.php </code> file <code> add_action( 'load-edit.php', 'posts_for_current_contributor' ); function posts_for_current_contributor() { global $user_ID; if ( current_user_can( 'contributor' ) ) { if ( ! isset( $_GET['author']...
Contributor disable seeing others' posts
wordpress