Articles of php

Only display title when there are results

Currently I have the following code to show related posts: <?php $cat_ids = array(); $postID = get_the_ID(); $categories = get_the_terms($postID, ‘article-category’); //this will give all the terms foreach($categories as $cat) { $cat_ids[] = $cat->term_id; //you may put some condition and consider only some specific terms as per your requirement } $args = array( ‘post_type’ => […]

Why BuddyPress fields not saving?

I have a WordPress+BuddyPress site. I added some extra fields in user profile. When i registering user i fill all fields on register form. After i do redirection in user profile: function auto_login_new_user( $user_id ) { wp_set_current_user($user_id); wp_set_auth_cookie($user_id); global $current_user; get_currentuserinfo(); wp_redirect( home_url() . ‘/members/’ . $current_user->user_login . ‘/profile/edit/group/1/’ ); exit(); } add_action( ‘user_register’, ‘auto_login_new_user’ […]

Add a custom class to the body tag using custom fields

There are certain posts where I want to manually append a custom body class to using custom fields. How do I go about it appending the class to the body tag when a certain custom field is added to a post? I have tried the following but the custom fields name tagbody is not shown […]

Extend Menu Walker Output

I’ve found a custom Menu Walker on the Internet that was perfect for my multilevel menu. It fitted almost like a glove. I’ve made some tiny improvements but now I need to limit the number of characters inside the output: <li><a href=”http:\\…”><span>Blah Blah Blah Blah Blah Blah Blah Blah Blah</span></a></li> I’m having some problems to […]

How to get thumbnail with pure PHP in a WordPress database?

I need help to get thumbnails in a WordPress database with pure PHP because a need insert this in a Magento Application (Feed). Can someone help me? I need this: http://img.mywordpresstips.com/php/fashionista_web_header_by_lstar92-d3gkahi-263×130.jpg or part of this, example: /uploads/2015/09/fashionista_web_header_by_lstar92-d3gkahi-263×130.jpg /2015/09/fashionista_web_header_by_lstar92-d3gkahi-263×130.jpg More details: add_image_size(‘magento-image’, 263, 130, true); PHP Script used: function SimpleLoopWordpress (){ try { // PDO em […]

How do I make this Metabox show current DB value?

<p> <?php $options = get_option( ‘city’ ); $names = explode( PHP_EOL, $options ); ?> <label for=”City” class=”timeshare-row-title”><?php _e( ‘City:’, ‘timeshare-textdomain’ )?></label> <select name=”city” id=”city”> <?php foreach ( $names as $name ) { printf( ‘<option value=”%s” selected=”selected”>%s</option>’, $name, $name ); } ?> </select> </p> Save function: if( isset( $_POST[ ‘city’ ] ) ) { update_post_meta( $post_id, […]

How to make a conditional statement within $output in shortcodes.php?

I’ve got a shortcode that’s got HTML in an $output field that’s lovely. I just want to add one paragraph to it at the bottom that’s conditional on this statement: <?php if ( get_post_meta( get_the_ID(), ‘campus’, true ) ) : ?> I can’t quite figure out how to format a statement like that (if possible) […]

Edit Account – read and write to MySQL

I have user data that’s being saved to and read from the database as they are all standard WordPress fields. example: $user->user_email And here’s the code I have inside the form-edit-account.php: <p class=”form-row form-row-wide”> <label for=”account_uid”><?php _e( ‘UID-Nummer’, ‘woocommerce’ ); ?></label> <input type=”text” class=”input-text” name=”uidnumber” id=”uidnumber” value=”<?php echo esc_attr( $user->user_uidnumber ); ?>” /> </p> Here’s […]

how to get attached file url for current post?

Trying to get the attachment file url for current post, using this code: if ( is_singular(‘post’) ) { $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts( $args ); if ( $attachments ) { foreach ( $attachments as $attachment ) { echo wp_get_attachment_url( $attachment->ID ); […]

How to use title attributes in sidebar widget?

I have a custom post type “article” & I need to display some custom urls is a widget in the sidebar using php code widget. When I use this code withing the loop it works perfectly: <a href=”<?php echo site_url(‘/article/full-text/’); ?> <?php $slug = $post->post_name; echo $slug; ?>” title=”<?php the_title_attribute(); ?>”>Full Text</a> but when I […]