Tag Info

New answers tagged

2

What you need to use here is the WP_Comment_Query() function. So on the author.php page, you can easily get the author info and ID as followed: // get author info $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); // set ID $user_id = $curauth->ID; Then we add the user ID in the query ...


0

I don't know if you would consider using a plugin – but I recently stumbled upon the plugin ultimate member and it seems it can do a lot of things with user profiles, but also seems to be suitable to display user's comments on the profile page: • "Show author posts & comments on user profiles"


2

Nice sleuthing. Every single person on this SO site has been foiled by something exactly like this at one point or another with the WordPress template hierarchy. You might think of this backwards though. All the steps you found lead you back to the shortcode [pmpro_account] which gets output in the loop-myaccount.php by way of the_content(). That ...


0

post_class will add some default Wordpress CSS Classes to the HTML tag; like <div <?php post_class(); ?> If you want to add your own theme's custom classes, you can add those inside post_class, like so... <div <?php post_class('blog-entry'); ?>. You can use post_class in Loop as well as in Single/Page theme files. If used in Loop, it will ...


1

It's actually only important to use it if your theme's CSS or JS is reliant on something it outputs. It essentially stuffs relevant class names into the HTML tag you put it on based on the current post/category/blah/blah. So, on a single post template this: <article <?php post_class(); ?>> might output: <article class="post post-123 ...


1

First method, you are missing the second parameter for get_the_author_meta, which is the ID of the author. Second method, you are using undefined variables.. Check this code, should get you what you want. // Method 1 <ul class="authpcom"> <?php $queried_object = get_queried_object(); $author_email = get_the_author_meta( ...


0

Try use this (functions.php) : function product_title($id) { $custom='CustomField' return get_post_meta($id, $custom, true); } and call func in your template (in loop and etc...): <?php $p_title=product_title(get_the_ID()); ?> <h3>Product : <?php echo ($P_title); ?> </h3>


0

What about add else { after get_template_part( 'template-parts/content', 'video'); }? EDIT (1) : <?php /** * The template for displaying single posts. * * @package SN */ get_header(); ?> <?php while ( have_posts() ) : the_post(); ?> <?php if( has_post_format('video')) { get_template_part( 'template-parts/content', 'video'); }else{ ...


1

We can do that with the help of the get_media_embedded_in_content() function: /** * Display only the first media item in the content * * @link http://wordpress.stackexchange.com/a/199398/26350 */ ! is_admin() && add_filter( 'the_content', function( $content ) { // Get the avialable media items from the content add_filter( ...


1

Create single-yourcostomposttypename.php file in theme folder.


0

get_queried_object_ID() will return the ID on the page for posts, or get_queried_object() will return the page object containing all its post fields. Alternately, the ID of the blog page is stored in the option page_for_posts, which is internally how get_queried_object gets the ID of the post object to load.


0

Maybe you can try with get_posts() and foreach loop for the second query instead of WP_Query and then you will have something like this: <?php $secondary_query = get_posts('category_name=students'); foreach($secondary_query as $secondary_post): echo "<li>" . get_the_title($secondary_post->ID) . "</li>"; endforeach; ?> With above ...


0

@Milo's answer worked perfectly (see comment above). if (in_array($post->ID, $do_not_duplicate)) continue; meant that duplicate posts were still being counted in the loop, though not being displayed. To fix, remove this line, and exclude duplicate posts from the query with this argument: 'post__not_in' => $do_not_duplicate. Thank you @Milo for your ...


1

You shouldn't really need to "exclude" anything. Just make use of the built in loop tracking. WP_Query will "remember" where you left off. For example: if (have_posts()) { while (have_posts()) { the_post(); echo 'firstpost##'; the_content(); echo '##endfirstpost'; break; } } // do some other stuff if (have_posts()) { while ...


2

You are fetching all the terms of your taxonomy, Use this instead : $terms = wp_get_post_terms(get_the_ID(), 'city-type'); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term ) { echo '<span>' . $term->name . '</span>'; } } Note : First argument to the function is id of the ...


0

To display 'news', you'll have to add it to your loop arguments: $wp_query->query( 'post_type' => 'news', 'posts_per_page='.get_option('posts_per_page').'&paged='.$paged );


1

If you want to maintain 100% compatibility with all plugins, you need to use the loop on single.php. The reason is that there are loop_start and loop_end actions which get triggered on the first and last call to have_posts().


2

Stricktly speaking, you don't need the loop in single post pages, you only need the call to the_post(). The reason for the_post() is that the_post() sets the $post global value to the single post post object


0

Here you go.. function latest_sticky() { /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort( $sticky ); /* Get the latest */ $sticky = array_slice( $sticky, 0, 1 ); //Change the 1 to get more than one. /* Query sticky posts */ $the_query = new ...


0

If it's your main loop, you could add this to your function.php: function custom_pre_get_posts($query) { if($query->is_main_query() && /* is sticky conditional tag(sorry I need to check what is that) */) { $query->set('posts_per_page', "1"); } } add_action('pre_get_posts', 'custom_pre_get_posts'); Or you can make a new ...


0

Meta keys are arbitrary and not connected to Custom Post Type definition. For any post custom meta fields can be created with any valid string key. So basically discovery of the keys is completely up to documentation and/or reading source code.


0

What is "sermon date", is it the custom field? If so, your meta_key is the name of your custom field used for that date. If not, how are you getting the sermon date? Might be something like this: $args = array( 'post_type' => 'sermons', 'meta_key' => 'sermon_date', 'orderby' => 'meta_value', 'meta_type' => 'DATE' ); $query = ...


0

query_posts is a PHP function, not a javascript function, it's executed on the server, and the resulting output is sent to the browser. By the time the browser gets the chance to run your if( $(window).width() < 2000 ) { check, it's already too late. The server has finished its PHP script, sent it across, and moved on to new requests. There's also no way ...


0

You are using default category for custom post type. You can instead use a taxonomy query to get filtered result based upon your custom taxonomy terms. Try this - $cat_ids = array(); $postID = get_the_ID(); $categories = get_the_terms($postID, 'custom_taxonomy_name'); //this will give all the terms foreach($categories as $cat) { $cat_ids[] = ...


0

My suggesion is to use wp_localize_script() to pass the post id to your AJAX calls. Something like this.. function my_script_enqueue() { global $post; $translations = array( 'postID' => $post->ID ); wp_enqueue_script( 'myscript', '/url/to/your/script.js', array('jquery') ); wp_localize_script( 'myscript', 'MyAJAX', ...


1

As you can see, I tried declaring the $post variable as global to account for failures due to being outside of the Loop. The problem is not that the post is "outside of the loop", problem is that AJAX request is a completely separate HTTP request. When you do an AJAX request, is just like you are opening a new window on browser and open the url in ...


0

What about sending the post id of the single post trough ajax as well? So if you create a hidden input that contains the id, something like this: <input type="hidden" id="post_id" name="post_id" value="<?php echo $post->ID; ?>"> Then you can just pick the id and send it trough the ajax request, so your function will end up looking ...


0

The problem is that you are running a loop from secondary query in front-page.php and the loop from main in page-home.php. So, the post data in page-home.php won't be the data from the WP_Query in front-page.php. Additionally, you are trygin to get full template files as template parts, which is not correct. I mean, front-page.php is a full template will ...


0

What all you did can also generate many errors never delete functions.php, .htaccess file anyways try defining localhost if your wordpress in running on local pc maybe this will work



Top 50 recent answers are included