question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I know that each menu item is simply post present in <code> nav_menu_item </code> post type. It has has ID and can be removed with <code> wp_delete_post() </code> but posts deleted this way don't remove menus present under [Appearance > Menus]. Only menu items are removed. For instance I have "My Menu" under [Appearanc...
Please check wp_delete_nav_menu() function. If you want to get all nav menus you can check wp_terms table or <code> $menu_list = get_terms('nav_menu'); </code> to get a list of it.
How do I programatically remove Menus?
wordpress
I have a post featuring a product that I've created using advanced custom fields. I would like to have a link on the post that opens in a new window and displays the same product, just with a different look and info. (Note: I'm specifically looking to use a second template and not a different CSS because different info...
The way I see it you have two options here: Pass the id to a custom template and then create a custom <code> wp_query </code> loop and use <code> $_GET['id'] </code> as the id of the loop. For Example: <code> &lt;?php /* Template Name: Pop Up View */ //get id from your url $id=$_GET['id']; //start custom loop $query = ...
How to change post template
wordpress
I'm trying to get an image for I previously assigned to a category using ACF. here's what I'm doing: <code> $category_image = the_field('cat_small', $linkedcat); </code> where $linkedcat is something like category_280 When I echo $category_image, i see an array, like so: <code> 261, , catsmall, , , http://localhost/cur...
Whenever in doubt, consult the documentation and nice plugins like ACF are very well documented. It depends on how you set the image field, but from this page Field Types -> Image , looks like you set you field to return an object. Instead of using <code> the_field </code> , which prints the value, you need <code> get_...
Advanced Custom Fields - category image
wordpress
I'd like to understand the difference between: <code> &lt;?php bloginfo( 'stylesheet_url' ); ?&gt; </code> and <code> &lt;?php bloginfo('template_url'); ?&gt;/style.css </code> because I think the second one is more flexible (is i decide to move the file in a subdirectory, for example. or if I have more stylesheet to a...
<code> bloginfo('stylesheet_url') </code> will always return the current theme's stylesheet. If current theme is a child theme , for example, it will return <code> style.css </code> relative to the child theme's root rather than the parent theme's root. <code> bloginfo('template_url') </code> will always return the par...
different way to achive stylesheet_url
wordpress
I am trying to create tabs for admin settings page in wp, but I think I'm doing it wrong. The example below shows how I did it but I don't know how to change this to use it correctly with no conflict ie. $. <code> function my_plugin_load_js() { wp_deregister_script('jquery'); wp_register_script('jquery', 'http://code.j...
Never de-register core-bundled scripts in the WP-Admin. You shouldn't do it on the front end , either, unless you really, really know what you're doing. But especially in the WP-Admin, just use the core-bundled scripts. Also, when you use core-bundled jQuery UI, WordPress already knows that jQuery is a dependency. Just...
Enqueue Javascript Correctly for 3.5
wordpress
I want to query multiple posts with an array of IDs (note: I am querying a custom post type). Here's what I have, which isn't working: <code> $myarray = array('144', '246'); $args = array( 'post_type' =&gt; 'ai1ec_event', 'p' =&gt; $myarray ); // The Query $the_query = new WP_Query( $args ); </code> Any tips on how to ...
Please reference the Codex entry for post/page parameters for <code> WP_Query() </code> . The <code> 'p' </code> parameter takes a single post ID, as an integer. To pass an array of posts, you need to use <code> 'post__in' </code> : <code> $myarray = array('144', '246'); $args = array( 'post_type' =&gt; 'ai1ec_event', ...
How do I use WP_query with multiple post IDs?
wordpress
I'm working on modifying the Keyboard Shortcut Navigation plugin to fit my site. Here's the plugin: http://wordpress.org/extend/plugins/easy-keyboard-shortcut-navigation/ I don't want this plugin to run on page 2020. I've tried <code> &amp;&amp; !is_page('2020') </code> and <code> || !is_page('2020') </code> in the <co...
This works for a page on my site with ID 675: <code> function tst($content) { if (is_page(675)) print('howdy'); } add_action('wp_footer','tst'); </code> I would just interrupt the function right at the top. <code> function keyboard_shortcut_navigation(){ global $paged, $wp_query; if (is_page(2020)) return; // for a pos...
Exclude function from running on a certain page
wordpress
I had 'theshortfilm.co" before changing to my current url 'welovefilm.co'. I changed my address 6 months back, everything went fine. But now when I activated my networks, I get my old url in the code. Please see the image below. http://imgur.com/PW6oW But when I change the url manually to new address and add it to the ...
I'm not sure what exactly is the problem that you're having but hopefully this solution will work. Backup your database ( This is very important ) Download this script: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/ Use it to replace the old url "theshortfilm.co" to the newer one "welove...
Old Website Address Still Showing
wordpress
I support a WordPress 3.4.2 site, lifering.org, running on a GoDaddy Virtual Server. Recently I chose to upgrade the underlying O/S from CentOS 5 to CentOS 6. The rebuild was entirely automated and I don't know what it involved. I restored my site from backup, and since then the plugin WP-DBManager no longer backs up o...
I solved this with help from the main StackOverflow site. One of the commenters suggested that the open_basedir directive might be set in php.ini - and that was the issue. Here is the open_basedir setting: <code> open_basedir = "/var/www/vhosts/lifering.org/:/tmp/" </code> I created a hard link mysql (could have been a...
WP-DBManager Plugin Can't Find Mysql Path
wordpress
Is there a way to count all published posts from a custom taxonomy? While looking around I found this snippet but I didn’t manage to get it to work … <code> global $wpdb; $query = " SELECT COUNT( DISTINCT cat_posts.ID ) AS post_count FROM wp_term_taxonomy AS cat_term_taxonomy INNER JOIN wp_terms AS cat_terms ON cat_ter...
Use an instance of WP_Query to query the database. http://codex.wordpress.org/Class_Reference/WP_Query To query database for custom taxonomies use, <code> $query = new WP_Query( array( 'people' =&gt; 'bob' ) ); </code> For more details on available options see: Taxonomy Parameters http://codex.wordpress.org/Class_Refer...
Count posts in custom taxonomy
wordpress
I have a three level nav setup using Wordpress menu creator. Structure: A —1 ——Y ——Z —2 —3 B C I wish to display each level of the navigation alone, in different areas of the page. With current items highlighted. On pages A, B or C I want to display: A B C (I can use wp_nav_menu with depth=1 for this) On pages 1*, 2 or...
What I ended up doing was setting up three sidebars, each using an instance of Advanced Menu Widget and settings as follows: Sidebars 1. main nav: start at level 0, display 1 level deep, display all items 2. second level nav: start at level 1, display 2 level deep, only show strictly related sub items 3. third level na...
Display three different levels of navigation from wp_nav_menu separately?
wordpress
In the Media upload popup page, how do I set the attachment link to none and hide it in Wordpress version 3.5? The following filter worked fine in earlier versions of WP: <code> function my_attachment_fields_edit($form_fields,$post){ // Set attachment link to none and hide it. $html = "&lt;input type='hidden' name='att...
Include this small plugin, activate and test. A tested version in 3.6-alpha, works only on click on a thumbnail. <code> &lt;?php /** * Plugin Name: Remove Attachment Link-To and set to value 'none' */ add_action( 'admin_footer-post-new.php', 'wpse_76214_script' ); add_action( 'admin_footer-post.php', 'wpse_76214_script...
Set media upload attachment link to none and hide it in WP v3.5
wordpress
How do I remove the <code> Insert from URL </code> link in the new Wordpress 3.5 Add Media popup page? In earlier versions of Wordpress, this worked fine: <code> // removes URL tab in image upload for post function remove_media_library_tab($tabs) { if (isset($_REQUEST['post_id'])) { $post_type = get_post_type($_REQUEST...
This should work: <code> add_filter( 'media_view_strings', 'cor_media_view_strings' ); /** * Removes the media 'From URL' string. * * @see wp-includes|media.php */ function cor_media_view_strings( $strings ) { unset( $strings['insertFromUrlTitle'] ); return $strings; } </code>
Remove "Insert from URL" link in Media upload - WP 3.5
wordpress
In my attempt to alter navigations current-menu-item class, I found a possible solution stackexchange-url ("stackexchange-url , <code> add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); </code> He makes use of a filter who is called with a tag 'nav_menu_css_class' , But it got me wondering, where can...
There are multiple was to find filters: Use an IDE (see stackexchange-url ("Eclipse example")), set WordPress as a separate project and search in this project for <code> apply_filters </code> or <code> do_action </code> . Get a program to search in all files of a directory (grep, Notepad++) and do the same search with ...
Where can you find the available filter tags?
wordpress
Done my research and found this is how to call the built-in stackexchange-url ("ui tabs jquery script") in wp for the admin area but I'm stuck on implementing the other jquery scripts needed that I believe are built into wp. I know how to add the css and just added html, I just don't want to cause any problems with oth...
If there is problem only with html markup you should check example from official jQuery UI site here: http://jqueryui.com/tabs/ It looks like yours, but for work you must check if your site include stuff like jquery and jquery ui script, jquery css is important too. After that you should have script with: <code> $( "#t...
Using tabs for wordpress plugin
wordpress
I am trying to create a form on the taxonomy template that will be able to filter the posts the current user is viewing. I want to use a few drop downs and submit button to do so. My code looks like this - ` <code> &lt;form method="get" id="searchform" name="searchform" action="&lt;?php echo home_url(); ?&gt;/blog/vide...
That happens because wp_dropdown_categories, by default, defines the name of the dropdowns as 'cat'. You are showing 2 dropdowns in the form, and both are named 'cat', because you didn't define a name for them. So when you submit the form, you get two query vars named cat. For example, if you want the second dropdown t...
Filter/Sort Post Form On Taxonomy page
wordpress
I am making a small live preview area inside a meta box using jquery where i need to get content from tinymce editor. But it seem my script loads before tinymce, this returns null when i try to get content from editor field. Enqueue: <code> add_action('admin_enqueue_scripts', 'wpk_popup_admin_script', 100); function wp...
Adding scripts after TinyMCE: You might check out the <code> before_wp_tiny_mce </code> and <code> after_wp_tiny_mce </code> hooks. If you take a look at the file <code> /wp-includes/class-wp-editor.php </code> you can see that the <code> TinyMCE </code> settings scripts are not all loaded through the usual <code> enqu...
Enqueue Script After TinyMCE initialized
wordpress
I'm stuck in searching a way to access the quicktag buttons on the html editor with jQuery. I tryed to access the buttons with <code> .each() </code> and <code> .children() </code> but both won't work. <code> jQuery( document ).ready( function( $ ) { $( '#ed_toolbar input.ed_button' ).children().css( 'color', 'red' ); ...
I wrote a jQuery plugin to check every 0.5 seconds if the toolbar has the requested element. <code> (function( $ ) { /** * Wait until element has finish loading requested elements, then execute callback * @param string element Element to wait for * @param object callback Callback to execute * @param integer timeout Opt...
HTML editor accessing quicktag buttons
wordpress
I'm using Wordpress as a CMS for a simple website. I want to prevent users from being able to browse the directories such as the wp-content/uploads folder or any directories of my theme. My host does not allow me to use "Options" or "DirectoryIndex" within a .htaccess file. I have tried putting a .htaccess file in the ...
To disable directory browsing all you have to do is drop in a blank <code> index.html </code> file into the <code> wp-content\uploads </code> directory, each subsequent sub-directory also would need a blank index file, there are plugins that can automatically do this for you. ps. Get a better host, there is no reason t...
Disable directory browsing of uploads folder
wordpress
I am adding the ability to add add-on to my plugin. Right now i am using: <code> foreach(glob(GMW_PATH .'/plugins/*', GLOB_ONLYDIR) as $dir) { include_once $dir . '/connect.php'; } </code> The function loop trough all the folders inside the "plugins" folder in my plugin and includes the connect.php file that is inside ...
Depends on your plugin. I prefer to use plugins with the minimal functionality that meets my needs. Less configuration options, less documentation to read, and hopefully less bugs. You also need to think on the upgrade process. If you make a change in a big plugin I should look into upgrading it even if the change is i...
should i use GLOB_ONLYDIR to hook add-ons for wordpress plugin
wordpress
The primary goal is to hide that the site is driven by wordpress. I've got the login part all locked up, but the logout URL still has those blasted <code> wp </code> delineators that give away it's a wordpress site. Is there a way to somehow mask this URL? Perhaps by a conjunction of custom redirect where the client-si...
Replacing just the URL is not enough. You have to tell WordPress what to do with the new URL. Sample code, creates a log-out URL like <code> example.com/logout=1 </code> and redirects to front page or custom URL after logging the user out: <code> add_filter( 'logout_url', 't5_custom_logout_url', 10, 2 ); add_action( 'w...
Masking logout URL
wordpress
Im working on a website where I need to create a submenu that shows only the parent pages. When I click on one of the parents it has to show the children from that parent. Here is the menu hierarchy I used this widget plugin: Subpages Extended for showing the parents and children: Parent Parent1 from parent Child1 from...
i think you don't have to use any plugin for that, check out: http://codex.wordpress.org/Function_Reference/wp_nav_menu and <code> $depth </code> to control the levels you want to display.
Dropdown menu on click change
wordpress
In WPMU, we are using Site Categories (with Sitewide Tags), but for the life of me I can't see how the category of the sub-site (say, departments in a school) to which each blog belongs ends up in the posts. (Well, it doesn't. I've listed out the metadata from the database and checked the post data, categories (...), t...
Site Categories is only a tool for categorizing blogs and together with Sitewide Tags allows for copying sub-blog posts to a top level blog of a certain category and list out posts from certain blog categories. However, no categorizing data is copied with the posts, or linked to the posts via metadata - except the blog...
Site 'Categories': save an admin global setting with post metadata
wordpress
I'm wondering--what is the best way to prevent a file (say, a custom CSS file associated with a plugin) from being overwritten during the update process? Would setting the file's status as immutable do the trick, or would this just cause an error during update? What is the best way to go about doing this?
Basically you should not include the file in the plugin in the first place. If the reason you don't want it to be overwritten is because you modify it based on some local setting, then you should leave the immutable part of the file in it and create another file which will contain the mutable parts. Then you can use yo...
Wordpress plugin updates / set file as immutable to prevent certain files from changing?
wordpress
I am receiving this warning when I try to run a database query: Warning: Missing argument 2 for wpdb::prepare() The offending query is: <code> $result = $wpdb-&gt;get_var( $wpdb-&gt;prepare( "SELECT DISTINCT meta_value FROM $metatable WHERE meta_key LIKE '%matchme%' AND meta_value IS NOT NULL AND meta_value &lt;&gt; ''...
Remove the call to <code> $wpdb-&gt;prepare() </code> : <code> $result = $wpdb-&gt;get_var( "SELECT DISTINCT meta_value FROM $metatable WHERE meta_key LIKE '%matchme%' AND meta_value IS NOT NULL AND meta_value &lt;&gt; ''" ); </code> In this case, the <code> $wpdb-&gt;prepare() </code> function is not doing anything . ...
$wpdb-> prepare() warning in WordPress 3.5
wordpress
got myself in a bit of a pickle. I want to display posts on category.php from the categories 'latest news' and 'custom models' only. The other category, 'press releases' is shown in a separate column. I've the following code - hashed together from misc articles I've read - but it's showing ALL the posts rather than jus...
Function <code> get_posts </code> accepts comma separated categories' ids or slugs, not names. As it makes use of <code> WP_Query </code> , see Category Parameters .
Showing posts from 2 categories only on category.php
wordpress
after updating to WordPress 3.5 my automatic embeds are limited to a width of 500px, and the settings for this size have been removed with WordPress 3.5 Also, I can't find the Values in the <code> wp_options </code> table. Does anyone know how to change them again? Cheers, fischi
See the function <code> wp_embed_defaults() </code> in <code> wp-includes/media.php </code> : <code> function wp_embed_defaults() { if ( ! empty( $GLOBALS['content_width'] ) ) $width = (int) $GLOBALS['content_width']; if ( empty( $width ) ) $width = 500; $height = min( ceil( $width * 1.5 ), 1000 ); return apply_filters...
How can I change Max Embed Size in WordPress 3.5?
wordpress
This http://jsfiddle.net/ambiguous/7L4WZ/ works...it removes empty <code> &lt;p&gt;&lt;/p&gt; </code> tags and then some but I can not git it to work from my plugin. <code> $('p').each(function() { var $this = $(this); if($this.html().replace(/\s|&amp;nbsp;/g, '').length == 0) $this.remove(); }); </code> WP loads jquer...
Your javascript has an invalid character in it that can't be rendered by most fonts, unicode 8203, which is why you don't see it. If I copy your code out of jsfiddle, paste it in a js file, then drop it in a browser, I can see the character on the last line. As far as your enqueue question is concerned- yes, you should...
Problem getting .js file to load via a plugin
wordpress
I have a section on my frontpage that querys through recent posts and grabs the title and thumbnail of each. In my functions.php, I've specified a <code> width </code> and <code> height </code> for the thumbnail using: <code> add_image_size( 'thumbnail-small', 179, 147 ); </code> I have all different size images in my ...
If you want WordPress to hard-crop the images to those absolute image dimensions, you can set the <code> $crop </code> argument of <code> add_image_size </code> to true, by default it is false: <code> add_image_size( 'thumbnail-small', 179, 147, true ); </code>
How to scale image with equal width and height without distortion?
wordpress
I am coding a pretty complex wordpress site (at least, taxonomically speaking), and i need to display a list of categories, children of a parent category, but I am struggling with getting the code to do this. I tried doing something like: <code> &lt;?php $cat = get_query_var('cat'); $categories= get_categories('hide_em...
Why are you using the parameter parent=1? If you remove this parameter it should work. If you want children and grandchildren, you should use: <code> $categories = get_categories('hide_empty=0&amp;child_of='.$cat); </code> If you want only direct children, you should use: <code> $categories= get_categories('hide_empty=...
Show category children, one level
wordpress
When inserting media into a post, is there a way to change the default-view of the Media-Library from "All media items" to "Uploaded to this post"? There is another thread where this question was extracted from: stackexchange-url ("How to manage attachment relationships")
There were two minor mistakes in my previous answer: I forgot to trigger the <code> change </code> event for the parent. I called the function on every AJAX call, making other selections impossible. Here is the fixed code: <code> &lt;?php /** * Plugin Name: Pre-select post specific attachments */ add_action( 'admin_foo...
Change the default-view of Media Library in 3.5?
wordpress
According to old post: stackexchange-url ("How to secure WordPress XMLRPC?"), every API require authentication. So, what is the point of adding <code> X-Pingback </code> in every public request? <code> curl -I http://ma.tt .. X-Pingback: http://ma.tt/blog/xmlrpc.php Content-Type: text/html; charset=UTF-8 .. </code>
I think that when talking about XMLRPC in the context of wordpress you usually mean to talk about authoring tools utilizing the XMLRPC protocol, and not about the protocol in general. In case of pingbacks and trackbacks the XMLRPC protocol is utelized to send content (comment) to your site by some other entity which is...
X-Pingback and XMLRPC
wordpress
How do I get the code below to display just the current post that corresponds to the current URL and not all the post from the same category? Barakadam, It works but it brings all the posts in the category instead of the one that was clicked on. <code> &lt;?php $category = end(get_the_category()); $current_name = $cate...
What you probably want is this: 1) A main page that displays a list of all posts in a certain category. 2) A page showing the individual post in this list on which the user has clicked. To create page number, you don't have to do anything. WordPress has an automatic scheme for URLs for you. Just use : <code> http://you...
How to display a single(current) post from a category
wordpress
I have a plugin that currently doesn't support network activation. The best fix for this of course is to fix it :) which I plan to do. However I wonder if there is a temporary solution I can use to prevent network activation in the meantime, perhaps a workflow similar to: Detect if the activation is network-wide (how??...
A plugin header <code> Network: false </code> will be ignored by WordPress … unfortunately. But the activation hook gets a parameter <code> $network_wide </code> , and we can use that to deactivate the plugin during activation: <code> &lt;?php /** * Plugin Name: Prevent Network Activation * Plugin URI: stackexchange-ur...
Prevent network activation of plugin
wordpress
I'm new to the Wordpress world. I've read the template hierarchy document and read online, but, I wanted to get feedback from here on what the best way to do this would be. What I'm trying to do is create a page that simply lists all of the posts that my site has. I am creating my own theme and as a result the home pag...
You have to create a page template with Loop inside. Then create a page "All My Posts" and assign the template you've created to it in "Page Attributes" section of "Edit Page" admin page. You can link to this page from the Front Page using <code> get_page </code> function. Function Reference/get page .
Linking to page with all posts
wordpress
How to get a variable comment field of all comments of current post ? I want to display all (for current post) comment user website url in to current post. Thanks for help.
To get the comments use <code> get_comments() </code> and the current post’s ID. To get the URL fields only use <code> wp_list_pluck() </code> . To remove the empty fields use <code> array_filter() </code> without a callback. . <code> $comment_urls = array (); $all_comments = get_comments( array ( 'post_id' =&gt; get_t...
Get a variable field of all comments of current post
wordpress
I'm checking <code> /wp-includes/media-template.php </code> and just found this: <code> &lt;# if ( data.compat &amp;&amp; data.compat.meta ) { #&gt; {{{ data.compat.meta }}} &lt;# } #&gt; </code> Never seen <code> &lt;# #&gt; </code> or <code> {{{ }}} </code> before. What kind of PHP is this? Searching for this symbols...
Those are javascript templates that get compiled into HTML by a javascript library. I think WP uses underscore.js . Let's say you write a jQuery plugin, and you have to append HTML code to the document. Using such templates you can avoid stuffing that HTML code inside huge concatenated strings within your javascript co...
What is in media-template.php, and how does it work?
wordpress
I upgraded to the latest version of WordPress and now for some reason when I go to the menus page and it only seems to happen there, I get an error saying Notice: Undefined index: eventmeta_noncename in /home3/themes/savior/functions.php on line 1399 Here is the code. Line 1399 would be line 4 in the code http://pasteb...
This seems to have solved the issue.. Checking to see that it is set. <code> if ( !isset( $_POST['eventmeta_noncename'] ) || !wp_verify_nonce( $_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) { return $post-&gt;ID; } </code>
undefined index
wordpress
I'm creating a setting to set a logo. It works but there is a problem. I only need one image to be set so the gallery item should be disabled / hidden. Of course this should only effect this page, of even better this setting. <code> &lt;?php // above this I do a simple settings api ?&gt; &lt;input id="set_logo" type="t...
You can disable tabs using a filter hook. Replace wpse_76095_isOurMediaUpload() with however you determine that you're running the media popup. <code> add_filter('media_upload_tabs', 'wpse_76095_filterMediaUploadTabs'); /** * filter out unwanted media upload tabs * @param array $tabs * @return array */ function wpse_76...
Disable gallery in 3.5 media iframe
wordpress
This is essentially a repeat of stackexchange-url ("this question"), but it has not been answered. I am trying to create an SSO system between two separate WordPress installs that are on different servers using different databases. The main site has a full database including a users table containing over 300,000 users....
After a lot of searching and asking people who are far more clued up than myself, I have concluded that this is impossible mainly because it requires two concurrent DB connections. In the end, my SSO solution was to build a more traditional SSO system that creates users in the remote site using the user data from the m...
SSO system between 2 WordPress installs on different servers
wordpress
In WordPress 3.5, media management has changed entirely. Also, relating attachments to specific posts is (I believe) basically only being done for backward compatibility. Therefore, after uploading attachments from within the media modal to a post of any post type, it establishes a relationship where the post ID is the...
I was part of the panic show. Happy to say that we can stop the panic, there is a way to view this by choosing "Uploaded to this post" option in dropdown in Media Library: (props to Michael Fields)
How to manage attachment relationships for specific posts in WP 3.5+
wordpress
I would like to get just the number of posts published in one particular day. I'm using this code, but this retrieve lot of code: <code> $day = date('Ymd'); $query01 = array('numberposts' =&gt; -1, 'post_type' =&gt; array('post', 'video', 'image', 'review'), 'm' =&gt; $day); $mypost = get_posts($query01); $counter = co...
<code> $wp_query-&gt;found_posts </code> can be used to get the number of posts. But here are arguments you can use to optimize the query and avoid useless SQL retrievals: <code> cache_results' =&gt; false, // Turns off post caching 'no_found_rows' =&gt; true, // To optimize when pagination is not required 'fields' =&g...
Count posts published in one particular day: the lighter way
wordpress
I have a custom post type "Article" which has a custom field "issue" that is the id number of a "issue" post type that i am selecting using a simple select box. I want to add a drop down of issues to filter the article listing found here: <code> edit.php?post_type=article </code> Is this possible? Is this sort of thing...
I had to modify max answer to get the filter working. Renaming the select to issue_restrict_articles stopped it incorrectly filtering &amp; kept the filter controls on the screen. posts_where filter and a SQL query to actually filter. <code> function restrict_articles_by_issue() { global $wpdb; $issues = $wpdb-&gt;get_...
Filter by custom Field for Custom post type Admin Listing
wordpress
I have multiple custom tags setup (ptags) and custom posttypes (products) and made it so i can filters posts by multiple tags in a category. Currently the code retrieves tags from posts relating to the active category (pcategory) I have dropdown boxes from general to specific e.g.: <code> &lt;BRAND&gt; &lt;TYPE&gt; &lt...
I think the best way to do this is using the loop, in the loop you need to get the terms for all associated posts. <code> &lt;?php if (have_posts()) : &lt;while (have_posts()) : the_post(); //thecode endwhile; endif; ?&gt; </code>
How to adjust code to refresh a dropdown box with tags that are active on filtered category listing
wordpress
My question is this: Is it possible to have two separate installations of WP with two separate domains sharing the same content? Scenario: User on http://A.mysite.com publishes a post. http://B.mysite.com uses the exact same database and can show that post as if it was its own. I've been looking around for quite some t...
If your main requirement is to synchronise blog posts from a master site to a slave, then maybe look at the FeedWordPress plugin. It means that you would only add/edit posts on one website and they would be replicated to the other site. That will allow you to cleanly run different plugins on the two sites.
Two WordPress sites sharing the same content
wordpress
I have created a new 'page template' and (this is probably not the right way to do this, but this is the way I have got it working), and created a new page using that template. Within the page template (PHP file) I have made, I have put lots of PHP which makes the page function, like it has a simple login an view infor...
Assuming you have a page with the slug "teaching-portal", this plugin adds a rewrite rule for that page that allows one part to be added after it in the URL, what you refer to as "mygetdata". I've called it "lesson". <code> &lt;?php /** * Plugin Name: Custom PHP app on teaching-portal page * Plugin URI: stackexchange-u...
Custom PHP App with a wordpress site
wordpress
<code> class my_menu extends WP_Widget { function widget($args, $instance) { // Excerpt length filter $new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";"); if ( $instance["excerpt_length"] &gt; 0 ) { add_filter('excerpt_length', $new_excerpt_length, 999); } //... }} </code> This filter wo...
I posted an article about this a while ago: <code> function wp_trim_all_excerpt($text) { // Creates an excerpt if needed; and shortens the manual excerpt as well global $post; $raw_excerpt = $text; if ( '' == $text ) { $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', ...
add_filter on "the_excerpt" only works when post does not have excerpt
wordpress
I'm interested to know if there's a method to specify a specific link structure for only a single category. Currently I have my install set to /2012/12/post-title . However there is a single category I would like to set to /category-name/post-id/ . Part of this is that I don't plan to title any of these posts, but I al...
You can use URL rewrites to edit the displayed URL, but without changing your actual wordpress setup all your internal links will still point to the structure assigned in your permalinks settings. The most straightforward way to do this would be by using a custom post type. With CPTs you can set up a whole different st...
A single category with a specific permalink structure differing from the standard set for the rest of the site
wordpress
I have a plugin meta box (in the Wordpress admin) with the following fields and values: Name of the div class selector= featured_content Font family= Verdana Font color= #000 They are stored in the Wordpress post meta table. In the Wordpress front end, one of the content template has this div: <code> &lt;div class="fea...
The answer is really simple, I never thought at first. You will simply create a custom CSS function inside your plugin and then use PHP to output the meta values and hook that to wp head.
How to implement styling of div in the front end using plugin admin meta box settings?
wordpress
I am adding meta box via add_meta_box hook but it is not showing in the admin panel, I double check the source code and it seems hidden because of this line: <code> &lt;div class="postbox-container" id="postbox-container-2" style="display: none;"&gt; </code> These are all my attempts to remove this display:none but all...
This did the trick, in jQuery: <code> //get page title var edit_title_page=$("html head title").text(); //Confirm if this is right Edit page if (edit_title_page.indexOf("Edit Form") &gt;= 0) { $('#postbox-container-2').removeClass("postbox-container"); $('#postbox-container-2').css('width','100%'); $('#postbox-containe...
How to make remove display none to this div container in post meta box?
wordpress
I am trying to order by post meta name which I added for post. Post meta is "_merchant_id" an I know how to sort by merchan_id but I don't know how to sort by merchant name. I am sorting by merchant id like this: <code> public function column_orderby( $vars ) { if ( isset( $vars['orderby'] ) &amp;&amp; is_admin() ) { s...
I hope that my solution will be useful to somebody. <code> public function column_orderby( $vars ) { if ( isset( $vars['orderby'] ) &amp;&amp; is_admin() ) { switch ( $vars['orderby'] ) { ... case 'merchant': GLOBAL $wpdb, $query; $vars = array_merge( $vars, array( 'meta_key' =&gt; '_merchant_id', 'orderby' =&gt; 'meta...
How to order by post meta name in wp admin?
wordpress
You write a plugin which requires PHP 5.1. Someone tries to install it on a server with PHP 4. How do you deal with that in a safe and user-friendly manner?
<code> /** * Plugin Name: Foo */ // Check for required PHP version if (version_compare(PHP_VERSION, '5.1', '&lt;')) { exit(sprintf('Foo requires PHP 5.1 or higher. You’re still on %s.',PHP_VERSION)); } // The rest of your plugin code ... </code> I'm not sure since which WP version this happened, but in 3.5 the plugin a...
Best way to abort plugin in case of insufficient PHP version?
wordpress
So i want to retrive a list with the posts that are in the meta_key "_blocks" and in that there is a multidimensional array with "areas" called left, right ,top etc. And within them there are assigned post_id:s. Like this: <code> Array ( [left] =&gt; Array ( [0] =&gt; 450 [1] =&gt; 452 [2] =&gt; 460 [3] =&gt; 451 [4] =...
Solved So i ended upp with a simple SQL-query: <code> $sql = 'SELECT post_id FROM kwido_postmeta WHERE meta_value REGEXP '"'. $area['area'] .'";a:[[:digit:]]+:{[^}]*"'. $mainpost-&gt;ID .'"''; $results = $wpdb-&gt;get_results( $sql, ARRAY_A ); </code> That looks after the current post_id and area with a regex, then if ...
Only display posts that are in multidimensional meta_value
wordpress
In my custom theme I'm using <code> &lt;img src="&lt;?php bloginfo('stylesheet_directory'); ?&gt;/images/logo.jpg"/&gt; </code> to load my custom logo. I'm using a custom sidebar for <code> front-page.php </code> and that's why I used <code> &lt;?php include('sidebar-front.php') ?&gt; </code> to get it. But when I'm us...
<code> get_stylesheet_directory_uri() </code> returns a value, it doesn’t print anything. So you have to use: <code> echo get_stylesheet_directory_uri(); </code> <code> get_template_part() </code> is just a wrapper for <code> locate_template() </code> . But the latter has one advantage: It returns the path of the file ...
bloginfo('stylesheet_directory') vs. get_stylesheet_directory_uri() and include('file.php') vs. get_template_part()
wordpress
I have been tasked with creating a theme that will be a base to list the site owners ebay store products. I have fleshed most of the project out in plain old php to get everything working as regards to adding the listings via the ebay api, right now im integrating the code into functions.php of the custom theme. What i...
In functions.php you can create "your_set_tables_function()" and then hook it in the "after_switch_theme" hook. Example: <code> add_action("after_switch_theme", "your_set_tables_function"); </code>
Theme Activation, Create Database Tables
wordpress
Right now, when I perform "Empty All Caches" it doesn't send a PURGE request to varnish. The result is that varnish isn't being refreshed. Is there a way that I can make varnish purge it's cache when choosing "Empty All Caches"? Is there a way that I can hook into W3 Total Cache "Empty All Caches"?
A simple solution could be to check when you click the "empty all cache" Button with <code> $_GET </code> Like this: <code> function wpse_16722_purge_varnish() { // Is the button submitted, Get the value $purge = isset( $_GET['w3tc_note'] ) ? trim( $_GET['w3tc_note'] ) : ''; // Security-check, user can edit settings //...
Make W3 Total Cache "Empty All Caches" function purge varnish
wordpress
I am using a page hierarchy and I want to show the title of the parents and grand parents page (if there is any). The structure is something like Startpage Startpage > Second page Startpage > Second page > Third page Startpage > Second page > Third page > Fourth page The title should be something like On the Fourth pag...
possibly build on <code> get_ancestors() </code> ; example: <code> if( is_page() ) : echo $post-&gt;post_title; if( $ancs = get_ancestors($post-&gt;ID,'page') ) { foreach( $ancs as $anc ) { echo ' -&gt; ' . get_page( $anc )-&gt;post_title; } } endif; </code>
page title, parent tilte and grand parent title
wordpress
Which is best way to find URI in child Theme. <code> &lt;?php echo get_template_directory_uri(); ?&gt; &lt;?php bloginfo('template_directory'); ?&gt; </code> Below given code works but it has "stylesheet" in it, sounds like its a hake to find URI. Is this the only solution ? <code> &lt;?php echo get_stylesheet_director...
Yes, <code> stylesheet </code> is for child themes, <code> template </code> for parent themes. Andrew Nacin has explained that recently on wp-hackers : child themes were originally just <code> style.css </code> and <code> functions.php </code> . That's why "template" refers to the parent theme and "stylesheet" refers t...
Finding URI in Child Theme
wordpress
I have my menu set up like so: Shop Online (WPeC 'Products Page' page) Product Category (WPeC Category) Product Category (WPeC Category) Product Sub Category (WPeC Category) Product Sub Category (WPeC Category) ... Single product pages are viewable from any category or sub category page as they both show the product li...
Looking for a solution for the same problem, I came across this: <code> add_filter( 'nav_menu_css_class', 'add_parent_url_menu_class', 10, 2 ); function add_parent_url_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = current_url(); // Get homepage URL $homepage_url = trailingslashit( ...
wp_nav_menu() loses 'current-menu-*' classes on single product page within category
wordpress
Assume we have blank WP site and we want to setup SMTP settings programmatically in our plugin or theme. What's the easiest way to do it without changing core files?
First of all, if we take a look at implementation of <code> wp_mail </code> function, we will see that this function uses <code> PHPMailer </code> class to send emails. Also we could notice that there is hard coded function call <code> $phpmailer-&gt;IsMail(); </code> , which sets to use PHP's <code> mail() </code> fun...
What's the easiest way to setup SMTP settings programmatically?
wordpress
I've added a help section using the add_help_tab() function. I'd like to be able to click a link somewhere on the theme/plugin page and have the help panel open at whichever tab I need. Can someone help me out with the required JS for this? Each tab panel has a unique hash link associated with it so I'd need to use thi...
Maybe the Q is bordering the <code> off-topic </code> , but IMO interesting in WordPress context. I've tested this directly in FireBug, in the Dashboard page ( <code> wp-admin/index.php </code> ). <code> var $ =jQuery.noConflict(); // Remove 'active' class from all link tabs $('li[id^="tab-link-"]').each(function(){ $(...
Click link on plugin/theme page and open the contextual help on a specific tab
wordpress
I am creating a photo plugin for users to view their photos. The plugin works in a way that when I add a new user, a directory is created in the uploads folder inside <code> wp-content </code> with the user's username as the name of the folder. This is where that user's images will be stored. Here is the code: <code> f...
First an observation, using <code> $upload_dir.'/USER_PHOTOS'.$user-&gt;user_login </code> may lead to a mess of folders in <code> wp-content/ </code> . I suggest <code> wp-content/user-photos/user-login/ </code> . And the following example considers it this way. In your case, you already have the menu item, for comple...
How to read individual user's directory and display content to that specific user?
wordpress
I'm using <code> wp_list_pages('title_li=') </code> on my site. Some of my pages do have subpages, however I don't want to list them unitl I'm on an actual parent page that has subpages. So imagine my front-page: <code> — About Us — Gallery — Kitchen — Disclaimer </code> When clicking on Gallery (and Gallery has two su...
This would probably be better achieved using CSS. First, you hide all .children: <code> .page_item .children { display: none; } </code> Then, you show the current_page_item's children: <code> .current_page_item .children { display: block; } </code>
wp_list_pages: only show subpages on the parent page?
wordpress
I'm running WP 3.4.2 on a VPS. When I first moved to this VPS server and imported all my WP data from the old, the menus worked fine. However, for some reason, I cannot edit/add to the menus, and some items have been deleted. No matter how many times I try to re-add those items, they won't appear. WP does not report an...
I had a similar issue with a client's server, and the solution in their case was to increase the php <code> max_input_vars </code> setting in <code> php.ini </code> . The number of menu items times the number of attributes for each item was exhausting the allowed input vars, so the server was silently truncating the re...
Menu limit, cannot add new menu items
wordpress
I have created a custom posts type cities and the code for its deceleration is <code> register_post_type('City',$args); </code> <code> $labels = array( 'name' =&gt; _x('Cities', 'post type general name'), 'singular_name' =&gt; _x('City', 'post type singular name'), ...... ); </code> and I Installed prime-strategy-bread...
The Labels are for the use in the Adminsection of your Website. If you want to change the slug in the URL of your CPT, use this values in your <code> register_post_type </code> function call. <code> $rewrite = array( 'slug' =&gt; __( 'cities', 'your_textdomain' ), //...... ) $args = array( 'rewrite' =&gt; $rewrite, //....
Breadcrumb is not generating the correct post page url
wordpress
I am using wp e-commerce plugin to build a simple e-commerce website. The problem is that I want to allow all users to post their products on the website. Right now, only the admin can add products. Does anyone know if it's possible to give users the privilege to post products?
The products are nothing but custom post type. So you have to create a custom form (say in a page template) and create custom posts accordingly in the backend. You can have a look for the approach here: http://wpshout.com/wordpress-submit-posts-from-frontend/ https://gist.github.com/1045695
making users able to add their own products wp e-commerce
wordpress
I want to check whether the current page is "Single activity page" or not, I ned like ths, <code> if(is_single_activity()) </code> or <code> if(is_page('is_single_activity')) </code> Thanks
Try this <code> bp_is_single_activity() </code>
how to find the current page is isngle activity page in buddypress?
wordpress
Not sure what I'm doing wrong, but I could use some help. My plugin architecture is below... <code> register_activation_hook(__FILE__, 'my_post_options_box'); add_action('admin_menu', 'my_post_options_box'); //enqueue jquery ui here function my_load_js() { echo "called"; //THIS ECHO FIRES wp_enqueue_script('jquery'); w...
Hook <code> my_load_js() </code> to <code> wp_enqueue_scripts </code> as in the examples in the Codex, and not to <code> admin_init </code> . <code> add_action('wp_enqueue_scripts', 'my_load_js'); </code> ...pretty sure that will take care of it.
Cannot get jQuery UI to enqueue in my plugin!
wordpress
I'm seeking for a plugin show my points (reputation) of Stackexchange (not Stackoverflow) in my Wordpress blogs. or other projects in stackexchange like : Superuser Security Serverfault SharePoint or author plugin that show points like Google plus beside the picture of every authors. or help me about "how can i develop...
I don't know of a plugin but the easiest way is to just embed your stack flair: stackexchange-url ("stackexchange-url For a more detialed solution I recommend you just fetch the Stack API using the the WordPress HTTP API, the docs are here: http://codex.wordpress.org/HTTP_API The Stack API is very easy to work with and...
wordpress plugin that show my reputation (points) in any stackexchange project in my wordpress blogs
wordpress
Whenever I change my permalink option from the default to /%postname%/, it results into my page cannot be found. Wordpress would complain that it cannot modify the .htaccess (because there was none), so I created it in /var/www/. The .htaccess has the same owner / permissions as my wordpress folder. Please help, I've b...
Solved! inside /var/www/.htaccess Add the line: Options +FollowSymLinks for the mod_rewrite problem: Check for Apache Mod_ReWrite – Following lists all the loaded modules sudo apache2ctl -M Enable Mod_Rewrite sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load Restart Apache view ...
permalink results to "page not found"
wordpress
When I delete a user, WordPress can just delete the post or page of this user, not his custom post and his attachments. An idea for a special hook? <code> add_action( 'delete_user', 'my_delete_user'); function my_delete_user($user_id) { $user = get_user_by('id', $user_id); $the_query = new WP_Query( $args ); if ( have_...
The hook you choose is appropriate, and here is how to use it to delete all posts of all types (posts, pages, links, attachments, etc) of the deleted user: <code> add_action('delete_user', 'my_delete_user'); function my_delete_user($user_id) { $args = array ( 'numberposts' =&gt; -1, 'post_type' =&gt; 'any', 'author' =&...
How to delete all post and attachments of a user when I delete it?
wordpress
For some reason the following isn't loaded anymore in wordpress 3.5. Does anyone know how to fix the <code> get_the_post_thumbnail() </code> ? I'm using the follow code: <code> echo "&lt;div class='meta_apps'&gt;"; echo "&lt;a href='"; the_permalink(); echo "'&gt;"; echo "&lt;div class=\"meta-icon\"&gt;".get_the_post_t...
I could be mistaken, but I don't think <code> $post-&gt;post_id </code> works to retrieve the post's ID. I believe you want <code> $post-&gt;ID </code> . So that was probably your issue to begin with, though without seeing your <code> $attr </code> array, it's hard to say. Here's a reference for <code> $post </code> 's...
get_the_post_thumbnail wordpress 3.5
wordpress
Working on a plugin, which is intended to provide a registration on front-end, to let users register. I am trying to create a Virtual page, which would display the form. Trying to create URL like the following http://example.com/plugin_register/register Have been referring to, stackexchange-url ("How do you create a 'v...
Make sure you flush the rewrite rules WPAdmin-> Settings-> Permalink-> Save. Sometimes only flushing fix the 404 errors.
Virtual Page with Registration form
wordpress
My customer has a site, which has WP blog + vBulletin forum. Now he wants to allow vb users to have their own blog, by modifying current WP blog to WPMU network. So I want to create a button, which could be clicked by vb user and new site will be created in network for him. How can I create new site programmatically fo...
first create a user from this function <code> wpmu_create_user( $username, $password, $email ) </code> then used this function to create blog <code> wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' =&gt; 1 ), $current_site-&gt;id ); </code> for detail you can see this file /wp-admin/network/site-...
Create site programmatically for WPMU
wordpress
I have this in my functions.php that creates a shopping cart widget with the plugin Marketpress. <code> &lt;?php function marketpress_get_cart_subtotal($format_currency=true) { global $mp; $selected_cart = $mp-&gt;get_cart_contents(true); if (!$selected_cart) return; foreach ($selected_cart as $bid =&gt; $cart) { if (i...
It is probably because of either different versions of PHP or different configuration for the Error logging. Assuming you have same environment (cart status, blog status, logged in user status etc) To overcome this, Please initialize $totals with empty array in the start of the function. And, If you want error to show ...
Marketpress php warning on server, no problem on localhost
wordpress
I have a "report" Custom Post Type registered in this way: <code> register_post_type( 'report', array( 'label' =&gt; 'Reports', 'description' =&gt; '', 'public' =&gt; true, 'show_ui' =&gt; true, 'show_in_menu' =&gt; true, 'capability_type' =&gt; 'post', 'hierarchical' =&gt; false, 'rewrite' =&gt; array('slug' =&gt; '')...
<code> I have no idea how to give a reasonable permalink. </code> Give it a title. You don't have to use the title for anything but the permalink, and it will be used in the page title as well most likely but since it is already exposed in the permalink I don't see the harm. You never have to print it anywhere else if ...
Give a permalink to Custom Post Types without title
wordpress
Is this possible to do? I love how the new uploader works. I'm guessing it has to do with a jQuery call like the other way did. EDIT This is the code I am currently using <code> jQuery(document).ready(function($) { $('.custom_upload_image_button').click(function() { imageField = $(this).prev('input'); tb_show('', 'medi...
To get you started, the basic functions and overrides as far as I know currently.There might be better solutions, but I only had two days with 3.5 yet: <code> // open modal - bind this to your button if ( typeof wp !== 'undefined' &amp;&amp; wp.media &amp;&amp; wp.media.editor ) wp.media.editor.open( ##unique_id_here##...
Using Wordpress 3.5 Media Uploader in meta box?
wordpress
As you know, there is a metabox that suggests tags as you type to input box. Is anyone knows how this function gets the tag's ID (term_id) which is selected? I have looked at some of the core files but it seems only the tag name is retrieved and the ajax response returns only the name, no sign of id. But it's just impo...
It just passes the tag names to wp_update_post(), which eventually calls wp_set_post_tags(), which eventually converts the names to <code> term_id </code> s, using term_exists().
WP native tag suggest metabox. How does it process tag id?
wordpress
How can I make a custom edit page for my plugins admin UI page, if the requested page has a query argument of <code> $_GET['action'] == 'edit' </code> ? My plugins entry url looks like <code> /admin.php?page=parser-top-level-handle </code> Than I have listed all my items per row in a table. On row hover appear "edit|de...
You may not have access to <code> $_GET </code> . I think you may need <code> global $wpdb, $posts, $_GET; </code> Second, everything happens in the constructor, which is when the plugin loads, which is every time any page of the site loads. So, every time a page loads you are checking <code> $_GET['action'] </code> fo...
Wordpress actions for plugin admin UI page
wordpress
I made a new network in my website its default language was ar when I add a new website it does not fill it WPLANG automatically, I made it manually but how to make it fill automatically.
OK Thanks all I found the answer <code> update_option( 'WPLANG', 'ar' ); </code>
how to make a wplang for network fill automatically
wordpress
I have embedded videos in the post (from youtube and other websites). Is it possible to get only the embedded video from the post and display on the homepage? There is some text before the video in the post, I do not want to display the text or anything else from the post, but only want to get the video. How that can b...
Couple of assumptions before getting to solution. First, you have all embedded codes as iframe (almost all video sites export as iframe now) not as shortcode or object tag. Secondly, you want the video box not the video url which will be offcourse different for every video website. Put following code in functions.php <...
Get video from the post on homepage
wordpress
I can sucesfully get my dynamic sidebar to work like so: <code> &lt;div class="sidebar sidebar-first"&gt; &lt;ul class="widget-area first"&gt; &lt;?php dynamic_sidebar( 'pop-photos-sidebar' ); ?&gt; &lt;/ul&gt; &lt;/div&gt; </code> Now, I'm trying to get the sidebar to work with a different code that is inside a php co...
You don't need to echo <code> dynamic_sidebar() </code> . End your <code> echo </code> , call <code> dynamic_sidebar() </code> , and then start a new <code> echo </code> . To make it easier, just close/reopen your PHP tags: <code> &lt;?php if( fake if code ) { if( another fake if code ) { ?&gt; &lt;div class="sidebar s...
Dynamic Sidebars & Echo
wordpress
How in the world can I check if a product is in a certain product category on the single-product.php ? <code> &lt;?php if (is_product_category('audio')) { echo 'In audio'; woocommerce_get_template_part( 'content', 'single-product' ); } elseif (is_product_category('elektro')) { echo 'In elektro'; woocommerce_get_templat...
I don't think <code> get_categories() </code> is the best option for you in this case because it returns a string with all the categories listed as anchor tags, fine for displaying, but not great for figuring out in code what the categories are. Ok, so the first thing you need to do is grab the product/post object for ...
How to check if the product is in a certain category on a single-product.php in Woocommerce?
wordpress
I created a new custom post type called <code> event </code> , which works fine. I also created a custom <code> 404 </code> page template, which is shown if a event/page/post is not found. But now the hard part, i want to create a custom 404 page for event post type. So this 404 page is only shown if a event is not fou...
Two options: Use conditional code inside of <code> 404.php </code> , to output different content/markup for the post-type Intercept the template at <code> template_redirect </code> , and include a separate template file for a 404 for the post-type. Personally, I'd go with option 1, as it is easier and more intuitive.
Create second custom 404 page for selected post type
wordpress
I am new to wordpress, I am creating a plugin and for the short code, I am using the short code api. But when I insert this shortcode in my page, it displayes as it is, it does not display the required output. Can asny body tell me what i am doing wrong? Am I calling or creating the function on right place or not? Belo...
Your code seems Ok, but is your plug-in correctly installed? You have to upload your urp_functions.php in a folder inside the /wp-content/plugins/ folder and in your urp_functions.php file, you have to insert comments so it gets detected as a plugin. here is the example comment on WordPress codex : <code> &lt;?php /* P...
add short code not working
wordpress
Heres my current loop: <code> &lt;?php if ( ! empty ( $GLOBALS['post'] ) &amp;&amp; is_single() &amp;&amp; in_category( 'movies', $GLOBALS['post'] ) ) : $movies = new Wp_Query('tag=movie-reviews'); while ( $movies-&gt;have_posts() ) : $movies-&gt;the_post(); ?&gt; &lt;?php get_template_part( 'sidebar-reviews', get_post...
<code> $movies = new Wp_Query('tag=movie-reviews&amp;posts_per_page=5'); </code>
Limit Loop to 5 Posts?
wordpress
I'm trying to get post's permalinks outside of the loop via a wordress plugin. Nothing seems to be working. Here is the original code that does not link to any permalink. <code> public function get_comments_count($single){ if (isset($this-&gt;params['comments']) &amp;&amp; $this-&gt;params['comments'] == 'yes'){ return...
According to: http://wpseek.com/get_comment_count/ <code> $single </code> is the post ID. Try: <code> public function get_comment_count($single){ if (isset($this-&gt;params['comments']) &amp;&amp; $this-&gt;params['comments'] == 'yes'){ return '&lt;div id="disquscomments"&gt;&lt;a href="'.get_permalink($single).'#disqu...
Getting Post Permalink Outside of Loop Not Working
wordpress
I've found that any WordPress theme uses this functions, but I don't understand what is the purpose of it and what is it, in this case <code> 'themify' </code> ? Here are some examples in Themify <code> functions.php </code> : 1). <code> load_theme_textdomain( 'themify', TEMPLATEPATH.'/languages' ); </code> 2). <code> ...
In this case, <code> 'themify' </code> is the defined textdomain for the Theme, used to make the Theme translatable . (Codex reference: <code> load_theme_textdomain() </code> ). Making a Theme translation-ready requires a few steps. Define the Theme's textdomain : <code> load_theme_textdomain( 'themify', TEMPLATEPATH.'...
What is a Theme textdomain?
wordpress
I have an archive page showing all blog posts (in a specific category). With a growing number of posts, I want to separate these by publish year. For example (simplified), I'd like the following: 2012 post post post 2011 post I'm testing this system by changing my oldest post's publish date to mid-2011. Currently the s...
My original impression was that I believe that what is happening is that the Loop doesn't get incremented until <code> the_post </code> runs so your <code> &amp;&amp; $postyear == $i </code> check is actually looking at the previous post not the current one. You are going to have to reorganize this to get that check af...
Archive listing of posts by publish year (multiple years)
wordpress
I've written a plugin which retrieves an xml file, parses and creates a series of short posts from the content. Although each post is very short (sometimes just a single sentence, never more than a few sentences), there are around 1000 posts to create from the file. Using wp_insert_post takes enough time for this job t...
You can access the database with an INSERT statement and add multiple rows at once. Something like this pseudo-code: <code> INSERT INTO $wpdb-&gt;posts ( `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `post_name`, `post_modified`, `guid`, `post_type`, `post_mime_type` ) VALUES...
Is there a faster way than wp_insert_post to add content to a blog
wordpress
I want to get the template in the theme which being in use of the current edited post(_type)/Page. Lets say im editing a single Post, Then i want to retrive that it using the template <code> single.php </code> And if im editing a Custom Post Type that have its own <code> single-{post_type}.php </code> i want to retrive...
Basically this isn't available in admin. You can take a look at my profile, go to my github page and grab the "current admin info" plugin . But this won't help you much. This would show you the template name: <code> get_page_template_slug( get_queried_object_id() ); </code> On the front end you can use the following pl...
Get which template being in use within WordPress-admin
wordpress
I have a section of my site where I'm using child-categories and tags to sort content. I'm have a tertiary navigation for the tags (templates/nav-tags.php): <code> &lt;nav class="side left"&gt; &lt;ul id="filters"&gt; &lt;?php $tags = get_tags( array( 'hide_empty' =&gt; true ) ); if ($tags) { foreach ($tags as $tag) { ...
Yay, thanks to the help of a co-worker, I now have a solution to this :) Tertiary navigation for the tags (templates/nav-tags.php): <code> // only load tags from the current page $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' =&gt; 'easy_steps', 'paged' =&gt; $paged, 'categor...
How can I hide tags on a child-category page, if that tag has not been used?
wordpress
I have used $count before, but never run into this problem. I cannot get it to work. I have limited php background, so please be patient with me! Here is the $count setup code: <code> &lt;?php $count = 0; ?&gt; &lt;?php if ( have_posts() ) : // Start the Loop ?&gt; &lt;?php $count++; ?&gt; &lt;?php while ( have_posts()...
The variable <code> $count </code> is accessible in the scope of the current function only. So whatever happens inside <code> get_template_part() </code> cannot know that variable. You could use a global variable, which is accessible everywhere as <code> $GLOBALS['count'] </code> . But then you risk collisions with plu...
How do I display an image before the first post of the loop when I'm using get_template_part?
wordpress
How can I add a field to the WordPress Register form? For example, I want to add the "First Name" field in the users profile to the Register form, but I can't figure out how to do that. The field's name is first_name, but adding <code> &lt;input type="text" name="first_name" id="first_name" value="&lt;?php echo $_POST[...
I found an excellent, free plugin that gets the job done. http://wordpress.org/extend/plugins/user-registration-aide/ Very easy to use, adds fields to both the register and the profile pages.
Add Field to WordPress Register Form
wordpress
When I register a new user to my blog, I always receive an email. The code in simple terms should look like this. <code> on_new_user_registration(){ //send email to admin //I want to do something else. } </code> I would like to do more than receiving an email. Can someone point me to the right code. I have tried using ...
You want to use the <code> user_register </code> hook, probably. Then use the Filesystem API to make the folder. Be aware that filesystem manipulation is dependent upon server configuration and may not always work, but using the API should ameliorate that problem as much as possible.
how can I do something on new user registration?
wordpress
I'm getting the following error <code> Fatal error: Call to a member function get_page_permastruct() /link-template.php on line 276 </code> when I invoke the in class constructor the <code> wp_insert_post($new_post); </code> . <code> add_action( 'plugins_loaded', array ( 'test', 'init' ) ); class test{ public static fu...
This happens because <code> plugins_loaded </code> fires before the global variable <code> $wp_rewrite </code> exists. From <code> wp-settings.php </code> : <code> // Load active plugins. foreach ( wp_get_active_and_valid_plugins() as $plugin ) include_once( $plugin ); unset( $plugin ); // Load pluggable functions. req...
fatal error get_page_permastruct()
wordpress
I've having trouble with accented characters now if i do utf8_decode() before echoing the title the problem is solved but instead of changing this all over my theme, can't I do this in one place that upgrade proof? I'm not really familiar with hooks but I think thats they way to do it, havent found out how to do it tho...
The filter for <code> the_title </code> functions is this one: <code> add_filter( 'the_title', 'f711_title_filter' ); function f711_title_filter( $title ) { return utf8_decode( $title ); } </code>
How to add hook to the_title() and get_the_title()
wordpress
I am just learning to create a meta box to upload a file in <code> wp-content/uploads </code> folder through this code: <code> //display image meta box function display_image_box() { global $post; wp_nonce_field( plugin_basename( __FILE__ ), 'wp_custom_noncename' ); echo '&lt;input id="post_media" type="file" name="pos...
Why don't you read the answers you get? stackexchange-url ("In this answer") I said to you to use <code> get_post_meta </code> instead of <code> get_post_custom </code> . The reason is quiet simple: <code> get_post_meta( post_id, metakey, single ) </code> returns a single value if <code> single </code> is set to <code>...
How to Display an Image Uploaded through a Meta Box in a Template?
wordpress
This might be a newb question, but I'm not sure. I did wuite a bit of searching, but i can't find anything to answer my question... I am customizing a plugin I needed it to show a list of the categories in hierarchy, which I got working with all of the functions of the plugin. I'm using wp_dropdown_categories, but I'd ...
There is an argument <code> walker </code> for <code> wp_dropdown_categories() </code> . It accepts an instance of a custom walker, a class extending <code> Walker_CategoryDropdown </code> or the generic <code> Walker </code> . Let’s create such a class. We have to change just one method. <code> class WPSE_Cat_Slug_Wal...
How do I get the category slug from wp_dropdown_categories
wordpress
When defining the callback that produces the HTML content for an admin settings page, I'd like to abstract the HTML into a separate file, but the HTML uses some wordpress functions, specifically current_user_can and screen_icon. These are claimed to be undefined when called through the included file but work fine inlin...
Use <code> plugin_dir_path() </code> to include executable files. <code> plugins_url() </code> returns the web address, that’s not what you need. <code> &lt;?php include(plugin_dir_path(__FILE__) . 'forms/admin_form.php') ?&gt; </code>
Why does abstracting html from plugin code result in loss of access to wordpress functions?
wordpress